Chapter - 4: The Loop Control Structure

Write a program to find the range of a set of numbers. Range is the difference between the smallest and biggest number on the list.


B
Sections
9
Exercises

A

B

C

D

E

1

2

3

4

5

6

7

8

9

#include<stdio.h>
#include<conio.h>
int main()
{
	int i,num,max,min, how, range;
	
	printf("Enter how many number you want to enter : ");
	scanf("%d", &how);
	
	printf("Enter the number : ");
	scanf("%d", &num);
	
	max=min=num;
	
	for( i = 1; i < how; i++)
	{
		printf("Enter the number : ");
		scanf("%d", &num);
		if(num>max)
			max=num;
		if(num<min)
			min=num;
	}
	range = max - min;
	
	printf("\n\n%d is the range of the data.", range);
	getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo