
For a given number, try to find the range in which the number exists.
Here, we are learning how to find the range of a number.
The logic we apply to find the range is −
lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10;
Let the number n=45
Lower limit=(42/10)*10 / / Division returns quotient
=4*10 =40
upper limit=40 10=50
range−lower limit-upper limit−40-50
The following is a C program for printing a range of numbers−
#include<stdio.h>
main(){
int n,lower,upper;
printf("Enter a number:");
scanf("%d",&n);
lower= (n/10) * 10; /*the arithmetic operators work from left to right*/
upper = lower+10;
printf("Range is %d - %d",lower,upper);
getch();
}When the above program is executed, it produces The following results −
Enter a number:25 Range is 20 – 30
This is another C program for printing a range of numbers.
#include<stdio.h>
main(){
int number,start,end;
printf("Enter a number:");
scanf("%d",&number);
start= (number/10) * 10; /*the arithmetic operators work from left to right*/
end = start+10;
printf("Range is %d - %d",start,end);
getch();
}When the above program is executed, it produces the following results −
Enter a number:457 Range is 450 – 460
The above is the detailed content of How to print a range of numbers using C language?. For more information, please follow other related articles on the PHP Chinese website!