Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to calculate range of values

Posted By: Walborgd Fischer     Category: C Programming     Views: 4500

Write a program to calculate range of values.

Code for Program to calculate range of values in C Programming

main()                                                      
   {                                                           
       int count;                                                   
       floatvalue, high, low, sum, average, range;                              
       sum = 0;                                                
       count = 0;                                              
       printf("Enter numbers in a line :                       
                 input a NEGATIVE number to end\n");           
   input:                                                      
       scanf("%f", &value);                                    
       if (value < 0) goto output;                             
          count = count + 1;                                   
       if (count == 1)                                         
          high = low = value;                                  
       elseif (value > high)                                  
               high = value;                                   
            elseif (value < low)                              
                 low = value;  
      sum = sum + value;                                       
      goto input;  

                                            
   output:                                                     
      average = sum/count;                                         
      range = high - low;                                      
      printf("\n\n");                                          
      printf("Total values : %d\n", count);                    
      printf("Highest-value: %f\nLowest-value : %f\n",         
               high, low);                                     
      printf("Range        : %f\nAverage      : %f\n",         
               range, average);                                
   }                                                           
                                                               
   
Output                                                      


                                                               
   Enter numbers in a line : input a NEGATIVE number to end    
   35  40.50  25  31.25  68.15  47  26.65  29  53.45  62.50 -1 
                                                               
   Total values : 10                                           
   Highest-value: 68.150002                                    
   Lowest-value : 25.000000                                    
   Range        : 43.150002                                    
   Average      : 41.849998                                    
  
Share: 


Didn't find what you were looking for? Find more on Program to calculate range of values Or get search suggestion and latest updates.

Walborgd Fischer
Walborgd Fischer author of Program to calculate range of values is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!