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