C Program to Check if Number is Prime or Not using For Loop
Write a Program to Check if Number is Prime or Not using For Loop
// C Program to Check if Number is Prime or Not using For Loop #include <stdio.h> int main() { int n; printf("Enter the number :--> "); scanf("%d", &n); int i = 2, count=0; for(; i < n; ) { if(n % i == 0) { count++; break; } i++; } if(count == 1) { printf("%d is Not a Prime number", n); } else { printf("%d is a Prime number", n); } return 0; }
Output:
Enter the number :--> 11
11 Prime a number
Enter the number :--> 65
65 is Not a Prime number