Prime numbers in C Language
Write a prime numbers in C Language program to generate prime numbers between 1 and n. User has to enter range of prime numbers and then program will print the prime numbers Between 1 to n.
We can find infinitely many prime numbers. Another way of saying this is that the sequence
2, 3, 5, 7, 11, 13, 17 ,19 and so on …… So you can find infinite number of prime Numbers.
Prime numbers in C Language Code
#include<stdio.h> #include<conio.h> void main() { clrscr(); int i=0,j=0,c=0,n; printf(“\nenter range for prime numbers:”); scanf(“%d”,&n); printf(“\n The prime numbers between 1 to %d are: \n”,n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { if(i%j==0) c++; } if(c<=2) printf(“%d “,i); c=0; } getch(); }
Leave a Reply