C LANGUAGE BOOK |
WAP TO PRINT PRIME NOS UPTO N NUMBERS.
#include<stdio.h>
main()
{
int n;
printf("\nHOW MANY PRIME NUMBER WILL BE PRINTED : \n");
scanf("%d", &n);
PrimeAll(n);
return;
}
PrimeAll(int n)
{
int i, j, w = 0;
if(n == 0 || n == 1)
{
printf("\nNO PRIME NOS UPTO %d NUMBERS \n", n);
}
else
{
printf("\nTHE PRIME NOS UPTO %d NUMBERS ARE : \n" ,n);
for(i = 2 ; i <= n ; i++)
{
for(j = 2 ; j <= i ; j++)
{
if(i%j == 0)
w++;
}
if(w == 1)
printf("%d%s", i," ");
w = 0;
}
}
}
C LANGUAGE BOOK |
No comments:
Post a Comment