Program to enter an integer and print if it is prime or composite 1 Attachment(s) Program to enter an integer and print if it is prime or composite #include #include #include void main() { clrscr(); int num1,x; cout << "Enter an integer : " << endl; cin>>num1; for(x=2;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); } } } It then determines whether the integer is prime or composite. It finally outputs the approriate message by writing to the 'cout' stream. Sample Input 23 Sample Output 23 is a prime number. |
Re: Program to enter an integer and print if it is prime or composite Don't you think, this program will check even and odd numbers instead of composite and prime? ---------- Post added at 07:45 PM ---------- Previous post was at 07:42 PM ---------- ok, got it ... this will work fine :p |
All times are GMT +5. The time now is 01:35 AM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.