C Program to print all prime numbers within given number
#include<stdio.h> main() { int num,i,count=0,j; printf("Enter a number \n"); scanf("%d",&num); printf("The Prime numbers upto %d are\n",num); for(i=1;i<=num;i++) { count=0; for(j=1;j<=i;j++) { if(i%j==0) { count++; } } if(count==2) { printf("%d\n",i); } } }
Enter a number30The Prime numbers upto 30 are2357111317192329
Post a Comment
If you have any doubts, Please let me know
Thanks!