Thread: Please Correct This C program

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    2

    Exclamation Please Correct This C program

    Hello, everyone,
    I need your help in this C program which is incomplete, please help me to correct it
    Code:
    #define   MAXVAL    50                                         #define   COUNTER   11                                    
       main()                                                      
       {                                                           
           floatvalue[MAXVAL];                             
           int          i, low, high;                              
           int   group[COUNTER] = {0,0,0,0,0,0,0,0,0,0,0};  
      /* . . . . . . . .READING AND COUNTING . . . .  . .*/
    for( i = 0 ; i < MAXVAL ; i++ )                         
           {                                                                 
    /*. . . . . . . .READING OF VALUES . . . . . . . . */
    
              scanf("%f", &value[i]) ;                             
             /*. . . . . .COUNTING FREQUENCY OF GROUPS. . . . . */
    
              ++ group[ (int) ( value[i] + 0.5 ) / 10] ;           
           }                                                       
              /* . . . .PRINTING OF FREQUENCY TABLE . . . . . . .*/
    
           printf("\n");                                           
           printf(" GROUP     RANGE     FREQUENCY\n\n") ;          
           for( i = 0 ; i < COUNTER ; i++ )                        
           {                                                       
              low  = i * 10 ;                                      
              if(i == 10)                                          
                high = 100 ;                                       
              else                                                 
                high = low + 9 ;                                   
              printf("  %2d    %3d to %3d       %d\n",             
                      i+1, low, high, group[i] ) ;                 
           }                                                       
       }            
                                                   
    
    Output      
    43 65 51 27 79 11 56 61 82 09 25 36 07 49 55 63 74
    81 49 37 40 49 16 75 87 91 33 24 58 78 65 56 76 67 
    45 54 36 63 12 21 73 49 51 19 39 49 68 93 85 59  
    
    
                           
        GROUP           RANGE           FREQUENCY                             
          1          0   to   9          2                                  
          2         10  to  19           4                                  
          3         20  to  29           4                                  
          4         30  to  39           5                                  
          5         40  to  49           8                                  
          6         50  to  59           8                                  
          7         60  to  69           7  
          8         70  to  79           6                                  
          9         80  to  89           4                                  
         10         90  to  99           2 
         11         100 to 100           0
    the output should look like this

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You got me - I get the same as you.
    Code:
    $ gcc -Wall foo.c
    $ ./a.out 
    43 65 51 27 79 11 56 61 82 09 25 36 07 49 55 63 74
    81 49 37 40 49 16 75 87 91 33 24 58 78 65 56 76 67 
    45 54 36 63 12 21 73 49 51 19 39 49 68 93 85 59
    
     GROUP     RANGE     FREQUENCY
    
       1      0 to   9       2
       2     10 to  19       4
       3     20 to  29       4
       4     30 to  39       5
       5     40 to  49       8
       6     50 to  59       8
       7     60 to  69       7
       8     70 to  79       6
       9     80 to  89       4
      10     90 to  99       2
      11    100 to 100       0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2017
    Posts
    2
    Quote Originally Posted by Salem View Post
    You got me - I get the same as you.
    Code:
    $ gcc -Wall foo.c
    $ ./a.out 
    43 65 51 27 79 11 56 61 82 09 25 36 07 49 55 63 74
    81 49 37 40 49 16 75 87 91 33 24 58 78 65 56 76 67 
    45 54 36 63 12 21 73 49 51 19 39 49 68 93 85 59
    
     GROUP     RANGE     FREQUENCY
    
       1      0 to   9       2
       2     10 to  19       4
       3     20 to  29       4
       4     30 to  39       5
       5     40 to  49       8
       6     50 to  59       8
       7     60 to  69       7
       8     70 to  79       6
       9     80 to  89       4
      10     90 to  99       2
      11    100 to 100       0
    how to solve this ?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Solve what?

    Try telling us what you expect to see, rather than what you (and everyone else) currently sees.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program seems correct, but it's miscalculating??
    By cheer4BAS in forum C++ Programming
    Replies: 3
    Last Post: 01-15-2014, 12:08 PM
  2. please help me correct this program
    By loogan211 in forum C Programming
    Replies: 5
    Last Post: 02-09-2013, 11:53 PM
  3. correct this program anyone please....
    By jothimani1991 in forum C Programming
    Replies: 3
    Last Post: 01-08-2013, 06:49 PM
  4. another little program: is this correct?
    By fsx in forum C Programming
    Replies: 7
    Last Post: 05-19-2009, 07:50 AM
  5. Is this program correct ?
    By broli86 in forum C Programming
    Replies: 9
    Last Post: 08-02-2008, 06:01 PM

Tags for this Thread