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