Find range of set of numbers
C program to find the range of a set of numbers. Range is the difference between the smallest and biggest number in the list.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,max=0,min=0,i;
printf("Enter the numbers you want to enter\t:");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
printf("Enter the number\t:");
scanf("%d",&num);
if(i==0)
{
max=num;
min=num;
}
if(num>max)
max=num;
if(num<min)
min=num;
}
printf("\nMaximum number in the list\t:%d",max);
printf("\nMinimum number in the list\t:%d",min);
printf("\nRange\t\t\t:%d",max-min);
getch();
}
Output
Enter the numbers you want to enter :8
Enter the number :45
Enter the number :54
Enter the number :25
Enter the number :12
Enter the number :63
Enter the number :5
Enter the number :1
Enter the number :58
Maximum number in the list :63
Minimum number in the list :1
Range :62