pastebin

Paste Search Dynamic
Recent pastes
calcAverage
  1. #include <stdio.h>
  2.  
  3. typedef struct{
  4.         int mth;
  5.         int eng;
  6.         int phy;
  7.         int avg;
  8. } Score;
  9.  
  10. void calcAverage(Score s[], int n);
  11.  
  12. int main(void) {
  13.         Score s[] = {
  14.         {65,80,95,0},
  15.         {70,68,75,0},
  16.         {60,100,83,0},
  17.         {100,55,74,0},
  18.         {90,85,100,0}
  19.         };
  20.         int i, n=5;
  21.  
  22.         calcAverage(s, n);
  23.  
  24.         for(i=0; i<n; i++ )
  25.                 printf( "[%d] %4d %4d %4d %4dn", i, s[i].mth, s[i].eng, s[i].phy, s[i].avg );
  26.  
  27.         return 0;
  28. }
  29.  
  30. void calcAverage(Score s[], int n){
  31.         int i;
  32.         for(i=0;i<n;i++){
  33.                 s[i].avg=(s[i].mth+s[i].eng+s[i].phy)/3.0;
  34.         }
  35. }
  36.  
Parsed in 0.007 seconds