Find out all the prime numbers from 1 to N numbers using C language
#include <stdio.h>
void main()
{ int n,c = 0;
printf("Enter the range : \n");
scanf("%d",&n);
for (int i=1; i<n; i++)
{
for (int j=2; j<=i; j++)
{
if (i == j){
printf("%d\n",i);
c++;}
else if (i%j == 0)
break;
}
}
printf("\nThe number of prime number from 1 to %d is :%d",n,c);
}
Comments
Post a Comment