Hello friends, Welcome to your Techgsr.co blog. And today in this article we will learn about how do i write in cpp Program to enter an integer and print if it is prime or composite .So let’s go to our topic
#include <iostream.h> #include <conio.h> #include <process.h> void main() { clrscr(); int num1,x; cout << “Enter an integer : ” << endl; cin>>num1; for(x=2;x<num1;x++) { if(num1%x==0) { cout << num1 << ” is a composite number.” << endl; getch(); exit(0); } else { cout << num1 << ” is a prime number.” << endl; getch(); exit(0); } } }
This program takes in an integer num1 as a screen input from the user.
It then determines whether the integer is prime or composite.
It finally outputs the approriate message by writing to the ‘cout’ stream.
INPUT :
23
OUTPUT :
23 is a prime number.
Related Post:-
So I hope that you learn about the this program And if you have any more queries about progrmming ,web Devlopment ,tech,computer relegated then feel free to discuss your problem in the comment section.Thank you so much and come back for more updates about Techgsr.co .