3. (E) Write a program to check whether the entered number is prime or not.
#include<stdio.h> | |
int main() { | |
int num, i, count = 0; | |
printf("Enter a number:"); | |
scanf("%d", &num); | |
for (i = 2; i <= num / 2; i++) { | |
if (num % i == 0) { | |
count++; | |
break; | |
} | |
} | |
if (count == 0) | |
printf("%d is a prime number", num); | |
else | |
printf("%d is not a prime number", num); | |
return 0; | |
} |
3. (E) Write a program to check whether the entered number is prime or not.
Reviewed by admin
on
December 23, 2019
Rating:
No comments: