1、上机考试练习题20021程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0int main(void)int repeat, ri;double x, y; scanf(“%d“, for(ri = 1; ri int main(void)int celsius, fahr; /*-*/scanf(“%d”,celsius=5.0*(fahr-32)/9;printf(“celsius = %dn“, celsius); 20023程序填空,不要改变与输入输出有关的语句。输入存款金额 money、存期 year 和年利率 rate,根据下列公式计算存款到期时的利息 int
2、erest(税前),输出时保留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”,interest=money*pow(1+rate),year)-money;printf(“interest = %.2fn“, int
3、erest); 20024程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0= 0时,f(x) = x0.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“, for(ri = 1; ri =0) y=sqrt(x);else y=pow(x+1),2)+2*
4、x+1/x;printf(“f(%.2f) = %.2fn“, x, y);20025程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0int main(void)int repeat, ri;double x, y; scanf(“%d“, for(ri = 1; ri int main(void)int num1, num2; /*-*/scanf(“%d%d“, printf(“%d + %d = %dn“, num1, num2, num1+num2);printf(“%d - %d = %dn“, num1, num2, num1-num2);printf(“%
5、d * %d = %dn“, num1, num2, num1*num2);printf(“%d / %d = %dn“, num1, num2, num1/num2);printf(“%d % %d = %dn“, num1, num2, num1%num2);return 0;20031程序填空,不要改变与输入输出有关的语句。计算表达式 1 + 2 + 3 + + 100的值。输出示例:sum = 5050#include int main(void) int i, sum;/*-*/sum=0;for(i=1;iint main(void) int i, m, sum;int repea
6、t, ri;scanf(“%d“, for(ri = 1; ri int main(void) int i, m, n;int repeat, ri;double sum;scanf(“%d“, for(ri = 1; ri int main(void) int i, n;int repeat, ri;double sum;scanf(“%d“, for(ri = 1; ri int main(void)int flag, i, n, t;int repeat, ri;double item, sum;scanf(“%d“, for(ri = 1; ri int main(void) int
7、lower, upper;int repeat, ri;double celsius, fahr; scanf(“%d“, for(ri = 1; ri int main(void)int i, n;int repeat, ri;double mypow, x;scanf(“%d“, for(ri = 1; ri #include int main(void)int i, n;double mypow;scanf(“%d“, /*-*/for(i=0;iint main(void)int i, n;double myfact;double fact(int n);scanf(“%d“, /*-
8、*/for(i=1;i#include int main(void)int i;double sum;/*-*/sum=0;for(i=100;i#include int main(void)int repeat, ri;double a, b, c, d;scanf(“%d“, for(ri = 1; ri =0)printf(“x1 = %0.2fn“, (-b+sqrt(d)/(2*a);printf(“x2 = %0.2fn“, (-b-sqrt(d)/(2*a);else printf(“x1 = %0.2f+%0.2fin“, -b/(2*a), sqrt(-d)/(2*a);pr
9、intf(“x2 = %0.2f-%0.2fin“, -b/(2*a), sqrt(-d)/(2*a); 30002程序填空,不要改变与输入输出有关的语句。输入一个正整数 repeat (0 0输入输出示例:括号内是说明输入3 (repeat=3) 10 (x=10) 0 (x=0) -98 (x=-98) 输出sign(10) = 1 (x = 10时 y = 1)sign(0) = 0 (x = 0时 y = 0)sign(-98) = -1 (x = -98时y = -1)#include int main(void)int repeat, ri;int x, y;scanf(“%d“,
10、 for(ri = 1; ri 0) y=1;else if(x=0) y=0;else y=-1;printf(“sign(%d) = %dn“, x, y);return 0;30003程序填空,不要改变与输入输出有关的语句。输入10个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数。输入输出示例:括号内是说明输入Reold 123?输出letter = 5, blank = 1, digit = 3, other = 1#include int main(void)char c;int blank, digit, i, letter, other;blank = digit
11、= letter = other = 0; for(i = 1; i = a int repeat, ri;scanf(“%d“, for(ri = 1; ri int main(void)int choice, i;double price;for(i = 1; i int main(void)0int i, mark;for(i = 1; i =60) printf(“Passn”);else printf(“Failn”);30007程序填空,不要改变与输入输出有关的语句。输入一个正整数 repeat (0#include int main(void)int a, b, c;int re
12、peat, ri;double area, perimeter, s;scanf(“%d“, for(ri = 1; ri cs= perimeter/2;area=sqrt(s*(s-a)*(s-b)*(s-c);printf(“area = %.2f, perimeter = %.2fn“,area, perimeter);else printf(“These sides do not correspond to a valid trianglen“);return 0;30008程序填空,不要改变与输入输出有关的语句。输入一个正整数 repeat (0int main(void)int
13、repeat, ri;double rate, salary, tax;scanf(“%d“, for(ri = 1; ri int main(void)int i, mark, n;int na, nb, nc, nd, ne;scanf(“%d“,na = nb = nc = nd = ne = 0;for(i = 1; i =90) na+;else if(mark =80) nb+;else if(mark =70) nc+;else if(mark =60) nd+;else ne+;printf(“Number of A(90-100): %dn“, na);printf(“Num
14、ber of B(80-89): %dn“, nb);printf(“Number of C(70-79): %dn“, nc);printf(“Number of D(60-69): %dn“, nd);printf(“Number of E(0-59): %dn“, ne);30010程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0int main(void)char sign;int x, y; int repeat, ri;scanf(“%d“,for(ri = 1;ri int main(void)int gcd, lcm, m, n; int repeat,
15、 ri; scanf(“%d“, for(ri = 1; ri #include int main(void)int denominator, flag;int repeat, ri;double eps, item, sum;scanf(“%d“, for(ri = 1; ri =eps) item= flag*1.0/ denominator;sum=sum+item;denominator = denominator +3;flag=-flag;printf(“sum = %.6fn“, sum);40013程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0int
16、main(void)int x, sum;int repeat, ri;scanf(“%d“, for(ri = 1; ri 0) if(x%2) sum=sum+x;scanf(“%d“, printf(“The sum of the odd numbers is %d.n“, sum);40014程序填空,不要改变与输入输出有关的语句。输入一个正整数 repeat (0int main(void)int count, in;int repeat, ri;scanf(“%d“, for(ri = 1; ri = repeat; ri+)scanf(“%d“, /*-*/count =0;if(in0) in=-in;docount +;in=in/10;