
c++函数调用:编写求1-n和的函数,调用函数计算s=1+(1+2)+(1+2+3)+…+(1+2+3+…+10)
展开全部
#include<stdio.h>
void main()
{
int i;
int t;
int s= 0;
for(i = 1; i <= 10; i++)
{
t += i;
s += t;
}
printf("s = %d\n",s);
}
上面是C语言的,下面用C++ 的做
#include<iostream>
using namespace std;
void main()
{
int i;
int t;
int s= 0;
for(i = 1; i <= 10; i++)
{
t += i;
s += t;
}
cout<<"s="<<s<<endl;
}
void main()
{
int i;
int t;
int s= 0;
for(i = 1; i <= 10; i++)
{
t += i;
s += t;
}
printf("s = %d\n",s);
}
上面是C语言的,下面用C++ 的做
#include<iostream>
using namespace std;
void main()
{
int i;
int t;
int s= 0;
for(i = 1; i <= 10; i++)
{
t += i;
s += t;
}
cout<<"s="<<s<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询