C Program to Print All Prime Numbers Between n and m using For Loop
Write a Program to Print All Prime Numbers Between n and m using For Loop
// C Program to Print All Prime Numbers Between n and m using For Loop #include <stdio.h> #include <stdbool.h> bool isPrime(int n) { if(n == 1 || n ==0) return false; int i; for(i = 2; i < n; i++) { if(n % i == 0) { return false; } } return true; } int main() { int n,m; printf("Enter n :--> "); scanf("%d", &n); printf("Enter m :--> "); scanf("%d", &m); printf("Prime numbers between %d to 5d :--> ", n, m); int i = n, j = m; for(; i < j; i++) { if(isPrime(i)) { printf("%d ",i); } } return 0; }
Output:
Enter n :--> 22
Enter m :--> 56
Prime numbers between 22 to 54 :--> 23 29 31 37 41 43 47 53