need help with a C program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhendrix
    New Member
    • Oct 2006
    • 9

    need help with a C program

    Hey I have this asignment due on sunday at 11 pm and have no idea how to do it if anyone could help me out i would greatly appreciate it. The assignment is to create a 3 by 4 int array containing 1,2,3,4,5,6,7,8 ,9,10,11,12. I then have to use loops to get the average of each row and collumn in the array
  • pxllyte
    New Member
    • Nov 2006
    • 3

    #2
    Originally posted by jhendrix
    Hey I have this asignment due on sunday at 11 pm and have no idea how to do it if anyone could help me out i would greatly appreciate it. The assignment is to create a 3 by 4 int array containing 1,2,3,4,5,6,7,8 ,9,10,11,12. I then have to use loops to get the average of each row and collumn in the array
    to get you started, you're going to be using a 2-dimensional array which will look like this by calling array[3][4]:

    then you'll use for loops to put numbers into each array element and then you can do the calculations

    Comment

    • jhendrix
      New Member
      • Oct 2006
      • 9

      #3
      yeah see that where im stuck...on the for loop part, i understand how to make an array but i really cant figure out how to make a loop which will give the average of each collumn and row of that array.

      Comment

      • jhendrix
        New Member
        • Oct 2006
        • 9

        #4
        I give up can someone please just show me the code for this : /?

        Comment

        • aarthy82
          New Member
          • Nov 2006
          • 4

          #5
          Hi there,
          Here is the program which calculates the average of each row and column. See if it helps you,
          #include<stdio. h>
          int main()
          {
          int intArray[3][4]={{1,2,3,4},
          {5,6,7,8},
          {9,10,11,12}};
          int i=0,j=0;
          int sCol=0,sRow=0;
          for(i=0;i<3;i++ )
          {
          for(j=0;j<4;j++ )
          {
          sRow=sRow+intAr ray[i][j];
          }
          printf("The Average of the %d Row is %d\n",i,sRow/4);
          sRow=0;
          }
          for(i=0;i<4;i++ )
          {
          for(j=0;j<3;j++ )
          {
          sCol=sCol+intAr ray[j][i];
          }
          printf("The Average of the %d Column is %d\n",i,sCol/3);
          sCol=0;
          }


          Thanks and Regards,
          Aarthy

          Comment

          • jhendrix
            New Member
            • Oct 2006
            • 9

            #6
            thanks a ton that really helped me out alot I greatly appreciate your help. I just have one more thing to ask. How would i make it so the averages are returned as floats instead of intigers?

            Comment

            Working...