浙大c程序语言设计(第2版)题库答案
int i;
double sum;
sum=0;
for(i=100;i<=1000;i++)
sum=sum+sqrt(i);
/*---------*/
printf("sum = %.2f\n",sum);
}
20053 计算物体自由下落的距离
一个物体从 100m 的高空自由落下,编写程序,求它在前 3s 内下落的垂直距离(结果保留2位小数)。设重力加速度为10米/秒^2。
#include <stdio.h>
int main(void)
{
double height;
height=0.5 * 10 * 3* 3; /*---------*/
printf("height = %.2f\n", height);
}
20056 计算分段函数
输入一个正整数repeat (0<repeat<10),做repeat次下列运算:
编写程序,输入x,计算并输出下列分段函数f(x)的值(保留2位小数),请调用sqrt()函数求平方根,调用pow()函数求幂。
当 x>=0 时,f(x) = x^0.5,当 x小于0时,f(x) = x^5 + 2x + 1/x。
输入输出示例:括号内是说明
输入
3 (repeat=3)
10 (x=10)
-0.5 (x=-0.5)
0 (x=0)
输出
f(10.00) = 3.16
f(-0.50) = -3.03
f(0.00) = 0.00
#include <stdio.h>
#include <math.h>
int main(void)