# C Program to find prime number

Rate this post

## What is prime number?

Definition of prime number

• A number is considered as prime number when it satisfies the below conditions.It should be whole number
• It should be greater than 1
• It should have only 2 factors. They are, 1 and the number itself.

For Example:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29 etc

## Let us see the  C program below:

#include <stdio.h>

int main()
{
int i, num, p = 0;
scanf(“%d”, &num);
for(i=1; i<=num; i++)
{
if(num%i==0)
{
p++;
}
}
if(p==2)
{
printf(“Entered number is %d “\
“and it is a prime number.”,num);
}
else
{
printf(“Entered number is %d “\
“and it is not a prime number.”,num);
}
}
Output:
Entered number is 17 and it is a prime number.

## Related Posts

• 60
Problem Statement: If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number. Solution: /* Sum of 1st and last digit of a four digit number */ #include<stdio.h> #include<conio.h> main() { int n,a,sum=0; clrscr(); printf("\Enter a…
Tags: number, program, write, learn, example, programming
• 58
What is Armstrong number? Sum of a number's digits raised to the power total number of digits is armstrong number. Armstrong numbers example: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634 etc Explanation: 3 = 3^1 = 3 153 = 1^3 + 5^3…
Tags: number, program, learn, write, find
• 57
The if statement by itself will execute a single statement, or a group of statements, when the expression following if evaluates to true. It does nothing when the expression evaluates to false. Can we execute one group of statements if the expression evaluates to true and another group of statements…
Tags: program, write, learn, find, example, programming
• 55
Problem Statement : If a five-digit number is input through the keyboard, write a program to reverse the number. Answer: /* To reverse the digits of 5-digit number */ #include<stdio.h> #include<conio.h> main() { int n,a,b; long int revnum=0; clrscr(); printf("\n Enter a five digit number less than 32767"); scanf("%d",&n); a=n%10;…
Tags: number, program, write, example, learn
• 54
In this article we will learn about the NOT operator, written as !. This operator reverses the result of the expression it operates on. For example, if the expression evaluates to a non-zero value, then applying ! operator to it results into a 0. Vice versa, if the expression evaluates…
Tags: example, program, learn, programming, write