当前位置: 代码迷 >> 综合 >> C语言实验——计算1到n的和(循环结构) OJ
  详细解决方案

C语言实验——计算1到n的和(循环结构) OJ

热度:6   发布时间:2024-01-14 23:06:40.0

C语言实验——计算1到n的和(循环结构)

Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
从键盘上输入任意一个整数n,计算1到n的和。
Input
从键盘输入任意整数n。
Output
输出1到n的和。
Example Input
3
Example Output
6
Hint
Author

#include <stdio.h>
#include <stdlib.h>int main()
{int a,b = 0;int i;scanf("%d",&a);for(i = 0;i < a;i++){b = b + i + 1;}printf("%d",b);return 0;
}

  相关解决方案