1. 编写程序求解S=1⼀(1*2)+1⼀(2*3)+1⼀(3*4)+……+1(n*(n+1))

2024-12-31 20:44:18
推荐回答(3个)
回答1:

#include
#include

void main ( void )
{
int nNum;
float fResult = 0.0;

printf ( "input the n: " );
scanf( "%d", &nNum );

printf ( "Calculating...\n" );
while( nNum > 0 )
{
fResult = fResult + ( 1 / ( float( nNum ) * float( nNum + 1 ) ) );
nNum--;
}

printf( "Result is %.3f", fResult );
}

回答2:

#include
void main()
{
int i;
int n = 10; //假设n = 10
double S = 0;
for(i = 1; i <= n; i++)
{
S += 1.0 / (i * (i+1));
}
printf("%f", S);
}

回答3:

int i;
int n;
double sum;
cout<<"请输入一个N 的值:";
cin>>n;
for (i=1;i{
s=s+1/i*(i+1);
}
cin>>s;