本程序要求实现:1*2*3+3*4*5+...99*100*101
#include <stdio.h>
int main()
{
long i;
long term,sum = 0;
for ( i = 1 ; i <= 99 ;i = i + 2)
{
term = i * (i+1) * (i+2);
sum = sum +term;
}
printf("sum = %ld\n",sum);
return 0;
}
本程序要求实现:a + aa + aaa + aaaa + ...+aaa(n个a)的值,n 和 a 值由键盘输入
理解题意:a*a*a*a*a*a*a*a,别以为是5+55+555+5555了
#include <stdio.h>
int main()
{
long term=1,sum = 0;
int a,i,n;
printf("请输入a,n:");
scanf("%d,%d",&a,&n);
for ( i = 1 ; i <= n ; i++)
{
term = term*a; // 我也想写term*=a 啊,可是题目不让
sum = sum + term;
}
printf("sum = %ld\n",sum);
return 0;
}
本程序要求实现:计算 1 -1/2 + 1/ 3 - 1/4 +...+1/99 -1/100+...,直到最后一项的绝对值小于10^-4为止。
#include "stdio.h"
#include "math.h"
int main()
{
int n = 1;
float term = 1.0, sign = 1 ,sum = 0;
while ( fabs(term) >= 1e-4 )
{
term = sign / n ;
sum = sum + term;
sign = - sign ;
n++ ;
}
printf("sum = %f \n",sum);
return 0;
}
第五小题题目不好打,大家对着书看吧
#include<stdio.h>
#include<math.h>
//求sinx的值
int main()
{
int n = 1, count = 1;
double x;
double sum, term;
printf("Input x:");
scanf_s("%lf", &x);//输入要求的x给sinx
sum = x;
term = x;
do {
term = -term*pow(x,2)/count;
sum = sum + term;
n = n + 2;
count*=n;
} while (fabs(pow(x, n) / count));
printf("sin(x)=%f,count=%d\n", sum, count);
return 0;
}
我觉得我写的没问题,但是345题都有扣分
**第三题还是意思理解的问题,还是5+55+555+5555
**楼主学习通痛失20分
#include <stdio.h>
int main()
{
long term=0,sum = 0;
int a,i,n;
printf("请输入a,n:");
scanf("%d,%d",&a,&n);
for ( i = 1 ; i <= n ; i++)
{
term = term*10+a;
sum = sum + term;
}
printf("sum = %ld\n",sum);
return 0;
}