Computer Science, asked by Urvichauhan28101, 11 months ago

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

Answers

Answered by sushiladevi4418
0

Answer:

C program to find the range of a set of numbers

Explanation:

#include<stdio.h>

main()

{

int largest=-30000,smalest=30000,range,num;

char choice='y';

clrscr();

while(choice=='y')

{printf("input a number=");

scanf("%d",&num);

if(num>largest)

largest=num;

if(smalest>num)

smalest=num;

printf("do you want to add another number y/n=");

scanf("%c",choice);

choice=getche();}

range=largest-smalest;

printf("range is %d",range);

getch();

}

Answered by codiepienagoya
1

Following are the program to find the range:

Output:

Enter total numbers: 5

Enter numbers: 66

88

99

10

2

Range is 97

Explanation:

The program to this question can be described as follows:

#include<stdio.h>//defining header file

int main() //defining main method

{

int i,max,min,num,val,range=0,a; //defining integer variable

printf("Enter total numbers: "); //print message

scanf("%d",&num); //input value from user end

printf("Enter numbers: "); //print message

scanf("%d",&val); //input value from user end

max=val;  //hold value in max

min=val; //hold value in min

for(i=1;i<num;i++) //define loop to input value from loop

{

scanf("%d",&a); //input value from user end

if(a<min) //define condition to check minimum value

{

min=a; //hold min value in min variable  

}

else if(a>max) // define condition condition for check max value  

{

   max=a; //hold value in max variable

}

}

range=max-min; // calculate range  

printf("Range is %d\n",range); //print range

return 0;

}

Description of the code can be described as follows:

  • In the above C language program, inside the main method first, we declared the integer variable, that is " i, max, min, num, val, range, and a", in which the num, val, and a variable are used to take input from the user end.
  • In this, variable num is used to take a total number of elements to insert, and val variable takes the first value and store this value in max and min variable.
  • In the next line, the for loop is declared, which inputs all value and uses the conditional statement to compare and store value in max and min variable.
  • In the last line, the range variable is used that subtracts max and min value and prints its value.

Learn more:

Range in C: https://brainly.in/question/3846104

Similar questions