by Dinesh Thakur Category: Control Structures

This code segment first accepts a range of values in variables m and n, both of type int. The variable num, also of type int, is used as the loop variable. It assumes values from m to n. For each value of loop variable num, the printf statement within the for loop is executed.

Thus, all the numbers from m to n are printed. Observe the space character after the %d format in the printf statement. This causes a space to be printed after each value of num. The output is given below.

#include <stdio.h>

void main()

{

        int num,m,n;

        clrscr();

        printf ("Enter range (m, n ) : ") ;

        scanf ("%d %d", &m, &n);

        for (num = m; num <= n; num++)

             {

                printf("%d ", num);

             }

            getch();

}

    C Program for Print integer number in a given range



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), 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.



Search Content





Popular Article