notes5

Printf ngrades for each student on each hw arenn 64

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lculate average for each homework */ for( j = 0; j < 4; j++ ) { temp = 0; for( i = 0; i < 3; i++ ) { temp += studentGrades[ i ][ j ]; } /* end inner for */ hwAverage[ j ] = (float)temp / 3; } /* end outer for */ /* calculate average of all scores */ temp = 0; for( i = 0; i < 3; i++ ) { for( j = 0; j < 4; j++ ) { temp += studentGrades[ i ][ j ]; } /* end inner for */ } /* end outer for */ totalAverage = (float)temp / (3*4); Multiple-Subscripted Arrays: Example 61 /* display results */ 62 63 printf( "\nGrades for each student on each hw are:\n\n" ); 64 printf( "%13s%5s%5s%5s\n", "hw1", "hw2", "hw3", "hw4" ); 65 66 for( i = 0; i < 3; i++ ) { 67 printf( "student%d", i+1 ); 68 for( j = 0; j < 4; j++ ) { 69 printf( "%5d", studentGrades[ i ][ j ] ); 70 } /* end inner for */ 71 printf( "\n" ); 72 } /* end outer for */ 73 for( i = 0; i < 3; i++ ) { 74 printf( "\nThe average grade for student%d is %.2f", i+1, 75 studentAverage[i] ); 76 } 77 printf( "\n"); 78 for( j = 0; j < 4; j++ ) { 79 printf( "\nThe average score on hw%d is %.2f", j+1, 80 hwAvera...
View Full Document

This note was uploaded on 03/02/2009 for the course ENGR 3 taught by Professor Ben-yaakov during the Fall '08 term at UCSB.

Ask a homework question - tutors are online