

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print the range of numbers using C language?
Problem
For given number try to find the range in which that number exists.
Solution
Here, we are learning how to find the ranges of a number.
The logic that we apply to find range is −
lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10;
Explanation
Let number n=45
Lower=(42/10)*10 // division returns quotient
=4*10 =40
Upper=40+10=50
Range − lower-upper − 40-50
Example
Following is the C program for printing the 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(); }
Output
When the above program is executed, it produces the following result −
Enter a number:25 Range is 20 – 30
Here is another C program for printing the 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(); }
Output
When the above program is executed, it produces the following result −
Enter a number:457 Range is 450 – 460
- Related Questions & Answers
- Print prime numbers in a given range using C++ STL
- How to print the content into the files using C language?
- Program to print prime numbers in a given range using C++ STL
- How to print the stars in Diamond pattern using C language?
- How to print the first ten Fibonacci numbers using C#?
- Print all Good numbers in given range in C++
- How to print the numbers in different formats using C program?
- Golang Program to Print the Numbers in a Range (1, upper) without Using any Loops
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Golang Program to Print Odd Numbers Within a Given Range
- Python Program to Print Numbers in a Range (1,upper) Without Using any Loops
- Find out the GCD of two numbers using while loop in C language
- How to print a name multiple times without loop statement using C language?
Advertisements