#include <stdio.h>
#include <math.h>
int main()
{
int n, flag, count = 0;
printf("Enter a number : ");
scanf("%d" , &n );
printf("\n\nThe prime numbers from 1 to %d are : \n\n", n );
for(int i = 2; i <= n ; i++ )
{
flag = 0;
for(int j = 2 ; j <= sqrt(i) ; j++ )
{
if( i % j == 0 )
{
flag = 1;
break;
}
}
if(flag == 0)
{
printf("%d ", i);
count++;
}
}
printf("\n\nTotal count : %d\n\n", count);
}
Comments
Post a Comment