- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
Following C++ program ask the user to enter a number to check whether it is a prime number or not, then display it on the screen:
Source Code: To find if a number is prime or not
/* C++ Program - To take a number as an input from user and Check if it is Prime or Not */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int num,i,count=0; cout<<"Enter a number:"; cin>>num; for(i=2;i<num;i++) { if(num%i==0) { count++; break; } } if(count==0) { cout<<"This is a prime number"; } else { cout<<"This is not a prime number"; } getch(); }Output
Enter a number: 7 This is a prime number