matrix!

This is a discussion on matrix! within the C Programming forums, part of the General Programming Boards category; The program need to find mean of elements in columns which are divided by 3. And to print which colmn ...

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    25

    matrix!

    The program need to find mean of elements in columns which are divided by 3. And to print which colmn has the greater mean
    Example
    For matrix:
    7 9 5
    17 15 30
    29 34 60

    Program print: 0 12 45. The greater mean: 3 column.

    I wrote this code and it prints 0 12 45 idk how to find which column has greater mean?

    Code:
    #include <stdio.h>
    #define max 50
    
    
    int main()
    
    
    {int n,m,i,j,k,d,br=0,suma;
    int a[max][max];
    int b[max][max];
        printf("Kolku redici i kolku koloni da imat matricite: \n");
        scanf("%d \n %d \n", &n,&m);
    
    
        for(i=0; i<m; i++)
        {
            for(j=0; j<n; j++)
            {
    
    
                scanf("%d", &a[i][j]);
    
    
            }
        }
    printf("Prvata matrica izgleda vaka: \n");
        for(i=0; i<m; i++)
        {
            for(j=0; j<n; j++)
            {
                printf("%d ", a[i][j]);
            }
            printf("\n");
    
    
    }
    
    
    
    
    for(i=0; i<n; i++)
    {
        suma=0;
        for(j=0; j<n; j++)
        {
            if((a[j][i]%3)==0)
            {
                suma+= a[j][i];
                br++;
            }
        }
    
    
        if(br)
        {
        int b=suma/br;
        printf("%d ", b);
        br=0;
        }
      else {
            int q=suma;
        printf("%d \n", suma);}
    }
    
    
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,671
    When you compute the mean for each column, use another variable to record which column has the largest.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    zub
    zub is offline
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    Just create array for means and find max value in it. By the way, why is array b[max][max]?
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-19-2014, 08:32 PM
  2. reading a matrix and printing out the matrix
    By Lina_inverse in forum C Programming
    Replies: 9
    Last Post: 10-23-2012, 05:09 PM
  3. adjacency matrix and sparse matrix
    By dpp in forum C Programming
    Replies: 3
    Last Post: 07-11-2010, 11:26 AM
  4. Need help in Matrix Addition & finding Inverse of a Matrix
    By ssatyan.129 in forum C Programming
    Replies: 6
    Last Post: 05-15-2009, 03:48 PM
  5. Matrix: Reloaded + Enter The Matrix (the game)
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-18-2003, 01:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21