# C program to print Prime Numbers Between 1 and n

/ * c program to print Prime Numbers Between 1 and n * /

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> void main() { int num,i=1,j,count; //clrscr(); printf("Enter Num value To Print Prime Numbers between 1 and Num: "); scanf("%d",&num); printf("Prime Numbers upto %d :\n \n",num); while(i<=num) { count=0; for(j=1;j<=i;j++) { //checking whether num is dvisible by j if(i%j==0) count++; } //if num is divisible by 2 numbers,then it is prime if(count==2) printf("%d ",i); i++; } printf("\n\n"); //getch(); } |

Output: ( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )

Check out programming video tutorials on this YOUTUBE Channel

Check out programming video tutorials on this YOUTUBE Channel

Best way to find prime numbers in C | Sieve Of Erasthothanese method to generate prime numbers |