-1

I would like to have some help.

I must find a way that the output must be:

A    B    C
90   60   80
50   100  70
100  20   100
10   50   75

Because the previous output is:

A 90 50 100 10
B 60 100 20 50
C 80 70 100 75

And it gives me some confusion on how to get to that output.

This is the codes that I have:

 char n[3]={'A','B','C'};
 int s[3][4]={90,50,100,10,60,100,20,50,80,70,100,75};
 float average=0;
 int x, y, max=0, min=0, total=0;

 for(x=0;x<3;x++)
 {
      printf("%c\t",n[x]);
      for(y=0;y<4;y++)
      { 
            printf("%d\t",s[x][y]);
      }
      printf("\n");
 }

It may be simple for you but I find this hard for me. Thanks in advance for all of your help. (P.S. I'm a student so try to use easy-to-understand words and another thing is I'm not good in english)

closed as off-topic by Bart van Ingen Schenau, Ixrec, gnat, user22815, user40980 Feb 1 '16 at 4:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking for assistance in writing or debugging existing code are off-topic on Programmers. These questions can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and the shortest code necessary to reproduce it in the question itself. See How To Create a Minimal, Complete, and Verifiable Example." – Ixrec, Community, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    You need to align columns horizontally. Either you use a large enough static value or you compute the maximum width of each column before printing them. Then, you print the header and each row in a loop. The printf function admits formatting directives to pad output with spaces. – coredump Jan 31 '16 at 10:26
  • @coredump In simplier words please – Carbine Alejandro Jan 31 '16 at 11:36
  • when compiling, always enable all the warnings, then fix those warnings. (for gcc, at a minimum use: -Wall -Wextra -pedantic (I also use: -Wconversion -std=c99 – user3629249 Jan 31 '16 at 17:14
  • for ease of understanding and readability, please follow the axiom: only one statement per line and (at most) one variable declaration per statement. – user3629249 Jan 31 '16 at 17:16
2

here is one method to produce the desired results

#include <stdio.h>

int main( void )
{
    char n[3]={'A','B','C'};
    int s[3][4] =
    {
        {90,50,100,10},
        {60,100,20,50},
        {80,70,100,75}
    };
    //float average=0;
    int x;
    int y;
    //int max=0;
    //int min=0;
    //int total=0;

    // to print in 'column' order

    printf( "%c\t%c\t%c\n", n[0], n[1], n[2] );

     for( x=0; x<4; x++ ) // column of array s[][x]
     {
          //printf("%c\t",n[x]);
          for( y=0; y<3; y++) // row of array s[y][]
          {
                printf("%d\t",s[y][x]);
          }
          printf("\n");
     }
} // end function: main

the above code produces the following output, where each field is separated from the following field by a <tab>:

A   B   C
90  60  80  
50  100 70  
100 20  100 
10  50  75  

Not the answer you're looking for? Browse other questions tagged or ask your own question.