by Dinesh Thakur Category: Control Structures

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 execution of the break statement causes inner for loop to terminate as it is the nearest loop enclosing the break statement. If the inner for loop is completely 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; 


        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)



                   if (d == num)

                      printf("%d ", num);




       C Program Prints Prime Numbers in a given range m to n

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles