code.club
標題:
輸入一數求其從一加到該數的總和
[打印本頁]
作者:
enter
時間:
2015-6-12 21:56
標題:
輸入一數求其從一加到該數的總和
#include <stdio.h>
#include <stdlib.h>
int main(void){
int x,i,sum;
sum=0;
printf("Enter a number:\n");
scanf("%d",&x);
for(i=1;i<=x;i++)
{
sum = sum + i;
if(i<x) printf("%d + ",i);
else printf("%d = ",i);
}
printf("%d",sum);
return 0;
}
歡迎光臨 code.club (https://code.club/)
Powered by Discuz! X3.2