最新消息:380元/半年,推荐全网最具性价比的一站式编程学习平台码丁实验室

C语言程序经典示例—-(5)数列求和

C 少儿编程 2450浏览 0评论
C语言程序经典示例

友情提示:380元/半年,儿童学编程,就上码丁实验室

#include <stdio.h>

main()

{

int i,j,n;

long sum=0,temp=0;

printf(“Please input a number to n:n”);

scanf(“%d”,&n);

if(n<1)

{

printf(“The n must no less than 1!n”);

return;

}

for(i=1;i<=n;i++)

{

temp=0;

for(j=1;j<=i;j++)

temp+=j;

sum+=temp;

}

printf(“The sum of the sequence(%d) is %dn”,n,sum);

getchar();

getchar();

}

 

转自公众号:
南昌青少年编程

您必须 登录 才能发表评论!