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

#include<stdio.h>
main()
{  
     int elme,i,num,n,large,small,Range;
    printf("Total Number of Element:");
    scanf("%d",&elme);
    printf("Enter first number=");
    scanf("%d",&n);
    large=n;
    small=n;
    for(i=1;i<=elme-1;i++)
    {
        printf("Enter another Number=");
        scanf("%d",&n);
       
        if(n>large)
        large=n;
        if(n<small)
        small=n;
    }
    printf("Largest=%d\n",large);
    printf("Smallest=%d\n",small);
    Range=large-small;
    printf("Range=%d",Range);
}

OUTPUT:

Total Number of Element:5
Enter first number=1
Enter another Number=2
Enter another Number=3
Enter another Number=4
Enter another Number=5
Largest=5
Smallest=1
Range=4
--------------------------------
Process exited after 6.479 seconds with return value 0
Press any key to continue . . .
 

Comments

Popular posts from this blog

Chapter 5 : Functions & Pointers (Let us C)

According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x ) Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.

Let Us C / Chapter 4 (The Case Control Structure)