fork download
  1. #include <stdio.h>
  2. //課題B-1: 1からnまでの和を求めるコードを完成させてください
  3. int sum(int n)
  4. {
  5. int total_sum;
  6. for(int i=0;i<=n;i++)
  7. {
  8. total_sum +=i;
  9. }
  10. return total_sum;
  11. }
  12.  
  13. int main(void) {
  14. int a,b;
  15. a = 10;
  16. b = sum(a);
  17. printf("1から%dまでの和は%d", a,b );
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1から10までの和は55