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