{"action":"opened","issue":{"url":"https://api.github.com/repos/renkonuma/Algorithms-and-Data-Structures/issues/1","labels_url":"https://api.github.com/repos/renkonuma/Algorithms-and-Data-Structures/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/renkonuma/Algorithms-and-Data-Structures/issues/1/comments","events_url":"https://api.github.com/repos/renkonuma/Algorithms-and-Data-Structures/issues/1/events","html_url":"https://github.com/renkonuma/Algorithms-and-Data-Structures/issues/1","id":71061657,"number":1,"title":"2_2.c","user":{"login":"renkonuma","id":12101990,"avatar_url":"https://avatars.githubusercontent.com/u/12101990?v=3","gravatar_id":"","url":"https://api.github.com/users/renkonuma","html_url":"https://github.com/renkonuma","followers_url":"https://api.github.com/users/renkonuma/followers","following_url":"https://api.github.com/users/renkonuma/following{/other_user}","gists_url":"https://api.github.com/users/renkonuma/gists{/gist_id}","starred_url":"https://api.github.com/users/renkonuma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renkonuma/subscriptions","organizations_url":"https://api.github.com/users/renkonuma/orgs","repos_url":"https://api.github.com/users/renkonuma/repos","events_url":"https://api.github.com/users/renkonuma/events{/privacy}","received_events_url":"https://api.github.com/users/renkonuma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-26T12:36:29Z","updated_at":"2015-04-26T12:36:29Z","closed_at":null,"body":"#include <stdio.h>\r\n#include <stdlib.h>\r\n\r\n/*  ************************************ */\r\n/*  compile                              */\r\n/*  > gcc -o <file> <file>               */\r\n/*  ************************************ */\r\n\r\n/*  ************************************ */\r\n/*  run                                  */\r\n/*  > ./<file> < 500rand10000.csv        */\r\n/*  ************************************ */\r\n\r\n/*  ************************************ */\r\n/*  result                               */\r\n/*  < average = 59                       */\r\n/*  ************************************ */\r\n\r\n/*  プロトタイプ宣言  */\r\nint getAverage(int* ary, int n);\r\n\r\nint main() {\r\n  int i;\r\n  int n, average;\r\n  int* p;\r\n\r\n  scanf(\"%d\", &n);\r\n  /* n個分のint変数の要領を確保する  */\r\n  p = malloc(sizeof(int) * n);\r\n  for (i = 0; i < n; i++) {\r\n    scanf(\"%d\", (p + i));\r\n  }\r\n  average = getAverage(p, n);\r\n\r\n  printf(\"average = %d\\n\", average);\r\n\r\n  /* 僕はどんなプログラムでも解放すべきだと思う  */\r\n  free(p);\r\n\r\n  return 0;\r\n}\r\n\r\nint getAverage(int* ary, int n) {\r\n  int i;\r\n  int average = 0;\r\n\r\n  for (i = 0; i < n; i++) {\r\n    /*  与えられた配列のポインタから\r\n        nだけずらして足し合わせていく   */\r\n    average += *(ary + i);\r\n  }\r\n  /* 平均なので、最後に個数で割る */\r\n  return average / n;\r\n}\r\n"}}