Thread: Find the total number of value greater or equal to a number in a 2D array.

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    6

    Find the total number of value greater or equal to a number in a 2D array.

    my code has to meet this requirement "The total number of values greater than or equal to 128 in the array."

    I am not sure how to how the code to find the total amount of number that is greater or equal to the value... can help would be appreciated.

    Code:
    #include <stdio.h>
    #include <math.h>
    #define m 5
    #define n 6
    
    
    int main(void)
    {
        int i, j,max, min, count=0 ;
        
        double total = 0, total_sqr=0, st_dev;
        
        int d[m][n] =
        {
            {15, 18, 30, 200, 234, 37},
            {12, 134, 128, 190, 111, 124},
            {77, 177, 130, 35, 64, 120},
            {123, 234, 228, 190, 211, 12},
            {78, 77, 13, 35, 164, 220}
        };
     
        int average;
        max = d[0][0];
        min = d[0][0];
        for(i=0; i<m; i++)
            for(j=0; j<n; j++)
               
            {
                count = 0;
                total=total + d[i][j];
                total_sqr = total_sqr + d[i][j]*d[i][j];
                if (min >d[i][j])
                    min = d[i][j];
                if (d[i][j]>max)
                    max = d[i][j];
                if (d[i][j]>128)
                    count++;
    
    
            }
    
    
        
        average = (float)total/(float) (m*n);
        st_dev = sqrt(total_sqr/(m*n)-average*average);
    
    
        printf("the average is %d\n",  average);
        printf("the standard deviation is %.2f\n", st_dev);
        printf("the minium value is %d\n", min);
        printf("the maxium value is %d\n", max);
        printf ("count = %d\n", count);
    
    
        return 0;
    
    }

  2. #2
    Banned
    Join Date
    Aug 2017
    Posts
    861

    OK I see it:

    LOOK what you are doing with your count var.
    what happens to it every time you go into that
    for loop....


    Last edited by userxbw; 11-10-2017 at 04:47 PM.

  3. #3
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,784
    Why is your program doing all those other calculations that have nothing to do with the problem description?

  4. #4
    Registered User
    Join Date
    Oct 2017
    Posts
    6
    all the other calculations are for other parts of my program. the one in the description is the one im stuck on

  5. #5
    Registered User
    Join Date
    Oct 2017
    Posts
    6
    Im not sure what you mean.... what am i suppose to do ?

  6. #6
    Banned
    Join Date
    Aug 2017
    Posts
    861
    locaicalization

    Code:
     for(j=0; j<n; j++)            
            {
    // what happens to the value each time it goes into this for loop?
              
                count = 0; 
    
                printf("My value is --> %d\n", count);
    
    
                total=total + d[i][j];
                total_sqr = total_sqr + d[i][j]*d[i][j];
                if (min >d[i][j])
                    min = d[i][j];
                if (d[i][j]>max)
                    max = d[i][j];
                if (d[i][j]>128)
                    count++;
             printf("Now my value is --> %d\n", count);
     
            }
    basic trouble shooting printf 's
    Last edited by userxbw; 11-10-2017 at 06:31 PM.

  7. #7
    Registered User
    Join Date
    Jun 2017
    Posts
    88
    Sorry, I think my post was not that helpful so I deleted it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help!! Find number in an array..
    By Elias Zaguri in forum C Programming
    Replies: 12
    Last Post: 10-14-2015, 09:09 AM
  2. Replies: 1
    Last Post: 07-07-2015, 12:31 PM
  3. Replies: 4
    Last Post: 10-22-2010, 05:32 AM
  4. Help: How to write a prime number greater than one billion
    By kenryuakuma in forum C++ Programming
    Replies: 6
    Last Post: 12-19-2008, 08:55 AM
  5. Can't find the lowest number in array?
    By Nate2430 in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2001, 10:21 AM

Tags for this Thread