P: 9

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
 
Share this Question
P: 3

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 2dimensional 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
 
P: 9

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.
 
P: 9

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

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+intArray[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+intArray[j][i];
}
printf("The Average of the %d Column is %d\n",i,sCol/3);
sCol=0;
}
Thanks and Regards,
Aarthy
 
P: 9

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?
    Question stats  viewed: 906
 replies: 5
 date asked: Nov 5 '06
