## Write a C C++ program to check entered number is prime or not

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

### Flowchart to check entered number is prime or not

### C program to check entered number is prime or not

```
#include<stdio.h>
int main()
{
int num, c=2;
char prime='t';
printf("Enter a number: ");
scanf("%d",&num);
while(c<num)
{
if(num%c==0)
{
prime='f';
break;
}
c++;
}
if(prime=='t')
{
printf("Prime number");
}
else
{
printf("Not a prime number");
}
return 0;
}
```

### C++ program to check entered number is prime or not

```
#include<iostream>
using namespace std;
int main()
{
int num, c=2;
char prime='t';
cout<<"Enter a number: ";
cin>>num;
while(c<num)
{
if(num%c==0)
{
prime='f';
break;
}
c++;
}
if(prime=='t')
{
cout<<"Prime number";
}
else
{
cout<<"Not a prime number";
}
return 0;
}
```

### Output of C C++ program to check entered number is prime or not

Enter a number: 5 Prime number

Enter a number: 10 Not a prime number

### Other programs using while for and do while loops in C C++

- Generate series of natural numbers (while, for, do while)
- Generate series of natural numbers and their sum
- Generate series of odd numbers and find their sum
- Generate series of even numbers and find their sum
- Generate table of given number
- Find factorial of given number
- Find power of given number
- Generate multiplication table of given number
- HCF and LCM of two numbers
- Generating Fibonacci series
- Generating series of prime numbers
- Sum of digits of given number
- Reverse of digits of given number
- Checking palindrome number
- Checking Armstrong number
- Generating series of Armstrong numbers
- Convert decimal to binary
- Convert binary to decimal