445,897 Members | 1,969 Online
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

need help with a C program

 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 Nov 5 '06 #1
5 Replies

 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 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 Nov 5 '06 #2

 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. Nov 5 '06 #3

 P: 9 I give up can someone please just show me the code for this : /? Nov 5 '06 #4

 P: 4 Hi there, Here is the program which calculates the average of each row and column. See if it helps you, #include 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 Nov 5 '06 #5

 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? Nov 5 '06 #6