浙江大学城市学院C语言期末上机考试题库之
浙江大学城市学院C语言期末上机考试题库之一 20021程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0
#include int main(void){ int repeat, ri; double x, y; scanf("%d", &repeat); for(ri = 1; ri <= repeat; ri++){ scanf("%lf", &x); if(x!=0) y=1/x;else y=0; printf("f(%.2f) = %.1fn", x, y); }}20022程序填空,不要改变与输入输出有关的语句。输入华氏温度,输出对应的摄氏温度。计算公式:c = 5*(f-32)/9,式中:c表示摄氏温度,f表示华氏温度。输入输出示例:括号内为说明输入150 (fahr=150)输出celsius = 65
#include int main(void){int celsius, fahr; scanf(“%d”,&fahr); celsius=5.0*(fahr-32)/9; printf("celsius = %dn", celsius);}20023程序填空,不要改变与输入输出有关的语句。输入存款金额 money、存期 year 和年利率 rate,根据下列公式计算存款到期时的利息 interest(税前),输出时保留2位小数。interest = money(1+rate)^year - money输入输出示例:括号内为说明输入1000 3 0.025 (money = 1000, year = 3, rate = 0.025)输出interest = 76.89
#include #include int main(void){ int money, year;double interest, rate; scanf(“%d%d%lf”,&money,&year,&rate); interest=money*pow((1+rate),year)-money; printf("interest = %.2fn", interest);}20024程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0= 0时,f(x) = x^0.5,当x小于0时,f(x) = (x+1)^2 + 2x + 1/x。输入输出示例:括号内是说明输入3 (repeat=3)10-0.50输出f(10.00) = 3.16f(-0.50) = -2.75f(0.00) = 0.00
#include #include int main(void){ int repeat, ri; double x, y; scanf("%d", &repeat); for(ri = 1; ri <= repeat; ri++){ scanf("%lf", &x);if(x>=0) y=sqrt(x);else y=pow((x+1),2)+2*x+1/x; printf("f(%.2f) = %.2fn", x, y); }}20025程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0