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