[ create a new paste ] login | about

Link: http://codepad.org/nXIJMHE8    [ raw code | output | fork ]

C, pasted on Jun 22:
#include <stdio.h>
struct Score {
  int english;
  int math;
  int physics;
};

#define N 3
int main() {
  struct Score obj[N];
  int i, p, s;
  for (i = 0; i < N; i++) {
    printf("%d: english: ", i + 1);
    scanf("%d", &p);
    obj[i].english = p;
    printf("%d: math: ", i + 1);
    scanf("%d", &p);
    obj[i].math = p;
    printf("%d: physics: ", i + 1);
    scanf("%d", &p);
    obj[i].physics = p;
  }
  s = 0;
  for (i = 0; i < N; i++)
    s += obj[i].english;
  printf("average english: %f\n", (double)s / N);
  s = 0;
  for (i = 0; i < N; i++)
    s += obj[i].math;
  printf("average math: %f\n", (double)s / N);
  s = 0;
  for (i = 0; i < N; i++)
    s += obj[i].physics;
  printf("average physics: %f\n", (double)s / N);
  return 0;
}
/* end */


Output:
1
2
3
1: english: 1: math: 1: physics: 2: english: 2: math: 2: physics: 3: english: 3: math: 3: physics: average english: -357814581.333333
average math: -357814581.333333
average physics: -357814581.333333


Create a new paste based on this one


Comments: