#include<stdio.h>
void main()
{
int i,n,sum=0; //声明三个整型变量,并为变量sum初始化赋值为0//
printf("Please enter n:"); //输入提示语//
scanf("%d",&n); //调用scanf()函数从键盘输入n的值//
for(i=1;i<=n;i++) //循环执行n次//
sum=sum+i; //反复累加i的值//
printf("Sum of numbers form 1 to %d is %d. \n",n,sum); //输入累加和//
}
原文地址:https://www.cnblogs.com/zhangdemingQ/p/12056275.html
时间: 2024-10-29 05:24:06