Print first 10 prime number by R4R Team

Prime number:

-A number that only divisible by the 1 or by itself is known as prime number.

Example-

prime numbers:
2,3,5,7,11,13,.......
Not prime numbers:
4,8,9,10,.....

-Here we show the first 10 prime number.

program-

#include < stdio.h>
int prime(int n)
{
int i;
for(i=2;i< n-1;i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
int i=0,n=3;
printf("First 10 prime number is :\n");
while(i< 10){
if(prime(n)){
printf("%d,",n);
i++;
}
n++;
}
}


output-

First 10 prime number is :
3,5,7,11,13,17,19,23,29,31

-In this program, we run the while loop inside the main function, and we pass every value in prime() function and it will return the prime number.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!