
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 Articles
- Print prime numbers in a given range using C++ STL
- Program to print prime numbers in a given range using C++ STL
- How to print the content into the files using C language?
- 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 a name multiple times without loop statement using C language?
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- Python Program to Print Numbers in a Range (1,upper) Without Using any Loops
- 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
- How to print array elements within a given range using Numpy?

Advertisements