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