To input an integer and print whether it is a prime number or not.
Dell D600 Laptop 1.6ghz 40gb DVD/CDRW B Grade Includes Genuine XP Professional restore cd!Write a program in C to input any positive integer and to print whether it is a prime number or not.
#include< #include< #include< void main( ) { int i, m, nd; nd=0; printf("Enter a positive integer\n"); scanf("%d", &m); for(i=1; i<=m; i++) { if(m % i = = 0) nd++; } if(nd ==2) printf("%d is a prime number\n", m); else printf("%d is not a prime number\n",m); } |
---|
0 comments:
Post a Comment