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