#include
usingnamespacestd;
intmain()
{
intn;
staticintsum=1;
cout<<"请输入N:"<<endl;
cin>>n;
for(inti=1;i<=n;i++)
{
for(intj=1;j<=i;j++)
{
sum=sum+j;
}
}
cout<<"结果2为:"<<sum;
system("pause");
return0;
扩展资料
C语言计算1-1/3+1/5-……的前n项之和
#include<stdio.h>
intmain(void){
inti,n;
doublef,s;
intflag=1,m=1;
printf("请输入分母的终值:");
scanf("%d",&n);
for(i=1,s=0;i<=n;i++)
{
f=flag*1.0/m;
s+=f;
flag=-flag;
m=m+2;
}
printf("1+1/3-1/5+...+1/n=%.2f\n",s);
system("pause");
return0;
}
C++编写程序,计算s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值
intmain(){ intn;staticintsum=1;cout<<"请输入N:"<<endl;cin>>n;for(inti=1;i<=n;i++){ for(intj=1;j<=i;j++){ sum=sum+j;} } cout<<"结果2为:"<<sum;system("pause");return0;
...=1+(1+2)+(1+2+3)+……+(1+2+3+……+n)的值,n的值由键盘输入。_百度...
main(){int n,i,s=0;scanf("%d",&n);for(i=1;i<=n;i++)s+=f(i);printf("%d\\n",s);} 已交付microsoft visual c++6.0运行
C++题目:输入n,计算s=(1)+(1+2)+(1+2+3)+…(1+2+3+…n)
可以推导后在编程,如上图所示;void main(){ int n;int sum;cout<<"输入n值:"<<endl;cin>>n;sum = (1+n)*n\/4 + n*(n+1)*(2*n+1)\/6;cout<<sum<<endl;}
c++函数调用:编写求1-n和的函数,调用函数计算s=1+(1+2)+(1+2+3)+...
int s= 0;for(i = 1; i = 10; i++){ t += i;s += t;} cout"s="sendl;}
...下列式子之和S=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)
您好,很高兴回答您的问题。
c++求和 s=1+1\/(1+2)+1\/(1+2+3)+...+1\/(1+2+3+4+5+...+n) 求程序设计...
class Caculate{ private:int n;float sum;public:void NUM(int a);\/\/:构造函数,初始化各数据成员;void fun();\/\/:根据上述公式求值并存放在S中;void print();\/\/:输出S中的值。};void Caculate::NUM(int a){ this->n=a;this->sum=0;} void Caculate::fun(){ this->sum=0;int...
...编写求1+(1+2)+(1+2+3)+……+(1+2+3+……+100)的程序
int i=1,s=0,sum=0;while(i<=100){ s=s+i;sum=sum+s;i++;}
求1+(1+2)+(1+2+3) +(1+2+3+4)+…+(1+2+…+n) 。要求:设计一个函数,专 ...
循环加花括号
怎么用C语言计算S=1+1\/(1+2)+1\/(1+2+3)+……+1\/(1+2+3+……+100)
include "stdio.h"int main(int argv,char *argc[]){double s;int i,t;for(s=t=0,i=1;i<101;s+=1.0\/(t+=i),i++);printf("The result are %f\\n",s);return 0;}运行结果:
C++编写程序以计算S=1+2^2+3^3+...+n^n
include<iostream> using namespace std;void main(void){int num;cout<<"请输入需要求的数:";cin>>num;cout<<"结果是:"<<obj.Sum(num)<<endl;}class Method{public long Sum( int num){int sum=0;for( int i=1;i<=num;i++)sum+=i*i;return sum;}} obj;...