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
need help with a C program
Collapse
X
-
to get you started, you're going to be using a 2-dimensional array which will look like this by calling array[3][4]:Originally posted by jhendrixHey 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
then you'll use for loops to put numbers into each array element and then you can do the calculations -
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,
AarthyComment
Comment