C Program to Print All Prime Numbers Between n and m using While loop
Write C Program to Print All Prime Numbers Between n and m using While loop
//Write a program to print all prime numbers between n and m using while loop #include <stdio.h> #include <stdbool.h> bool isPrime(int n) { if(n == 1 || n ==0) return false; int i = 2; while(i < n) { if(n % i == 0) { return false; } i++; } 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; while(i < j) { if(isPrime(i)) { printf("%d ",i); } i++; } return 0; }
Output:
Enter n :--> 22
Enter m :--> 56
Prime numbers between 22 to 54 :--> 23 29 31 37 41 43 47 53