[ create a new paste ] login | about

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

C, pasted on Dec 22:
#include<stdio.h>

int main(void)
{
  int i, j, cnt = 0, sum = 0;
  int score[4][3] = {
    {45,  50,  60},
    {75,  95,  45},
    {100, 90,  95},
    {60,  70,  80},};
  char name[] = {'A','B','C','D'};
  double a[4];

  for (i = 0; i < 4; i++) {
    for (j = 0; j < 3; j++)
      printf("score[%d][%d]=%d\n", i, j, score[i][j]);
  }

  printf("\n") ;

  for (i = 0; i < 4; i++) {
    for (j = 0; j < 3; j++) {
      printf("%c君の第%d回小テストの点数は%dです。\n", name[i], j + 1, score[i][j]) ;
      cnt++;
      sum += score[i][j] ;
    }
    a[i] = (double)sum / cnt;
    sum = cnt = 0;
  }

  for (i = 0; i < 4; i++)
    printf("%c君の平均点は %lf 点でした。\n", name[i], a[i]);

  return 0;
}


Output:
score[0][0]=45
score[0][1]=50
score[0][2]=60
score[1][0]=75
score[1][1]=95
score[1][2]=45
score[2][0]=100
score[2][1]=90
score[2][2]=95
score[3][0]=60
score[3][1]=70
score[3][2]=80

A君の第1回小テストの点数は45です。
A君の第2回小テストの点数は50です。
A君の第3回小テストの点数は60です。
B君の第1回小テストの点数は75です。
B君の第2回小テストの点数は95です。
B君の第3回小テストの点数は45です。
C君の第1回小テストの点数は100です。
C君の第2回小テストの点数は90です。
C君の第3回小テストの点数は95です。
D君の第1回小テストの点数は60です。
D君の第2回小テストの点数は70です。
D君の第3回小テストの点数は80です。
A君の平均点は 51.666667 点でした。
B君の平均点は 71.666667 点でした。
C君の平均点は 95.000000 点でした。
D君の平均点は 70.000000 点でした。


Create a new paste based on this one


Comments: