Q:

C program to print natural numbers within a range

belongs to collection: C Programming on Numbers

0

C program to print natural numbers within a range

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The mentioned C program prints the natural numbers in a given range. The minimum and maximum value of the range ask by users.

#include<stdio.h>
int main()
{
    int rangeMinValue,rangeMaxValue, i;
    printf("Please Enter the rangeMinValue of natural number = ");
    scanf("%d",&rangeMinValue);
    printf("Please Enter the rangeMaxValue of natural number = ");
    scanf("%d",&rangeMaxValue);
    if((rangeMinValue > 0) && (rangeMaxValue > 0) && (rangeMaxValue > rangeMinValue ))
    {
        printf("List of Natural Numbers from %d to %d are \n",rangeMinValue,rangeMaxValue);
        for(i = rangeMinValue; i <= rangeMaxValue; i++)
        {
            printf("%d ", i);
        }
    }
    else
    {
        printf("Enter Valid numbers\n");
    }
    return 0;
}

 

Output:

Please Enter the rangeMinValue of natural number = 5

Please Enter the rangeMaxValue of natural number = 10

List of Natural Numbers from 5 to 10 are 

5 6 7 8 9 10 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Programming on Numbers

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to find the sum of natural numbers upto ... >>
<< C program to print natural numbers from 1 to n...