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