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