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

Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will determine whether a point lies inside the circle, on the circle or outside the circle.

Chapter 5 : Functions & Pointers (Let us C)

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