Saturday, 15 March 2014

Write a program to calculate range of v

Write a program to calculate range of v
Code for Program to calculate range of values in C Programmingalues.

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 

No comments:

Post a Comment