The outer for loop is set up to process each number in the given range. Each number is tested within this loop using the simplified code. The break statement’s execution causes the inner for loop to terminate as it is the nearest loop enclosing the break statement. If the inner for loop is entirely executed, i. e., if condition d == num is true, num is printed as a prime number.
#include<stdio.h> #include<math.h> void main() { int num,m,n,d; clrscr(); printf("Enter the Range Between m,n "); scanf("%d%d", &m,&n); for (num = m; num <= n; num++) { for(d = 2; d < num; d++) { if (num % d == 0) break; } if (d == num) printf("%d ", num); } getch(); }