Prime number program.
// This code will tell if a number if prime number or not.
#include<stdio.h>
int main(){
int i, j, n, c=0;
printf("Enter a number : ");
scanf("%d",&n);
for (i=1; i<=n; i++){
if (n%i == 0){
c++;
}
}
if (c==2){
printf("Prime Number.\n");
}
else {
printf("Not prime number.\n");
}
// This code will print the print the prime number between 1 to 100.
printf("Prime nos between 1 to 100 is :\n");
for (i=1; i<=100; i++){
c=0;
for (j=1; j<=i; j++){
if (i%j == 0){
c++;
}
}
if (c==2){
printf("%d ",i);
}
}
return 0;
}
No comments:
Post a Comment