c语言程序设计题目及答案20021程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入x,计算并输出下列分段函数f(x)的值(保留1位小数)。当x不等于0时,y=f(x)=1/x,当x等于0时,y=f(x)=0。输入输出示例:括号内是说明输入2(repeat=2)10(x=10)0(x=0)输出f(10.00)=0.1f(0.00)=0.0#includestdio.hintmain(void){intrepeat,ri;doublex,y;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){scanf(%lf,&x);/*---------*/if(x!=0)y=1/x;elsey=0;printf(f(%.2f)=%.1f\n,x,y);}}20022程序填空,不要改变与输入输出有关的语句。输入华氏温度,输出对应的摄氏温度。计算公式:c=5*(f-32)/9,式中:c表示摄氏温度,f表示华氏温度。输入输出示例:括号内为说明输入150(fahr=150)输出celsius=65#includestdio.hintmain(void){intcelsius,fahr;/*---------*/scanf(“%d”,&fahr);celsius=5.0*(fahr-32)/9;printf(celsius=%d\n,celsius);}20023程序填空,不要改变与输入输出有关的语句。输入存款金额money、存期year和年利率rate,根据下列公式计算存款到期时的利息interest(税前),输出时保留2位小数。interest=money(1+rate)^year-money输入输出示例:括号内为说明输入100030.025(money=1000,year=3,rate=0.025)输出interest=76.89#includestdio.h#includemath.hintmain(void){intmoney,year;doubleinterest,rate;/*---------*/scanf(“%d%d%lf”,&money,&year,&rate);interest=money*pow((1+rate),year)-money;printf(interest=%.2f\n,interest);}20024程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入x,计算并输出下列分段函数f(x)的值(保留2位小数),请调用sqrt函数求平方根,调用pow函数求幂。当x=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#includestdio.h#includemath.hintmain(void){intrepeat,ri;doublex,y;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){/*---------*/scanf(%lf,&x);if(x=0)y=sqrt(x);elsey=pow((x+1),2)+2*x+1/x;printf(f(%.2f)=%.2f\n,x,y);}}20025程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入实数x,计算并输出下列分段函数f(x)的值,输出时保留1位小数。当x不等于10时,y=f(x)=x,当x等于10时,y=f(x)=1/x。输入输出示例:括号内是说明输入2(repeat=2)10234输出f(10.0)=0.1f(234.0)=234.0#includestdio.hintmain(void){intrepeat,ri;doublex,y;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){/*---------*/scanf(%lf,&x);if(x!=10)y=x;elsey=1/x;printf(f(%.1f)=%.1f\n,x,y);}}20026程序填空,不要改变与输入输出有关的语句。输入2个整数num1和num2,计算并输出它们的和、差、积、商与余数。输出两个整数的余数可以用printf(%d%%%d=%d\n,num1,num2,num1%num2);输入输出示例:括号内是说明输入53(num1=5,num2=3)输出5+3=85-3=25*3=155/3=15%3=2#includestdio.hintmain(void){intnum1,num2;/*---------*/scanf(%d%d,&num1,&num2);printf(%d+%d=%d\n,num1,num2,num1+num2);printf(%d-%d=%d\n,num1,num2,num1-num2);printf(%d*%d=%d\n,num1,num2,num1*num2);printf(%d/%d=%d\n,num1,num2,num1/num2);printf(%d%%%d=%d\n,num1,num2,num1%num2);return0;}20031程序填空,不要改变与输入输出有关的语句。计算表达式1+2+3+......+100的值。输出示例:sum=5050#includestdio.hintmain(void){inti,sum;/*---------*/sum=0;for(i=1;i=100;i++)sum=sum+i;printf(sum=%d\n,sum);}20032程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入一个正整数m(0=m=100),计算表达式m+(m+1)+(m+2)+......+100的值。输入输出示例:括号内为说明输入3(repeat=3)0(计算0+1+2+...+100)10(计算10+11+12+...+100)50(计算50+51+52+...+100)输出sum=5050sum=5005sum=3825#includestdio.hintmain(void){inti,m,sum;intrepeat,ri;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){scanf(%d,&m);/*---------*/sum=0;for(i=m;i=100;i++)sum=sum+i;printf(sum=%d\n,sum);}}20033程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入2个正整数m和n(m=n),计算表达式1/m+1/(m+1)+1/(m+2)+......+1/n的值,输出时保留3位小数。输入输出示例:括号内为说明输入3(repeat=3)515(计算1/5+1/6+1/7+...+1/15)1020(计算1/10+1/11+1/12+...+1/20)13(计算1+1/2+1/3)输出sum=1.235sum=0.769sum=1.833#includestdio.hintmain(void){inti,m,n;intrepeat,ri;doublesum;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){scanf(%d%d,&m,&n);/*---------*/sum=0;for(i=m;i=n;i++)sum=sum+1.0/i;printf(sum=%.3f\n,sum);}}20034程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入一个正整数n,计算表达式1+1/3+1/5+......的前n项之和,输出时保留6位小数。输入输出示例:括号内为说明输入2(repeat=2)5(计算1+1/3+1/5+1/7+1/9)23(计算1+1/3+1/5+...+1/45)输出sum=1.787302sum=2.549541#includestdio.hintmain(void){inti,n;intrepeat,ri;doublesum;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){scanf(%d,&n);/*---------*/sum=0;for(i=1;i=n;i++)sum=sum+1.0/(2*i-1);printf(sum=%.6f\n,sum);}}20035程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:读入一个正整数n,计算1-1/4+1/7-1/10+……的前n项之和,输出时保留3位小数。输入输出示例:括号内是说明输入2(repeat=2)310输出sum=0.893sum=0.819#includestdio.hintmain(void){intflag,i,n,t;intrepeat,ri;doubleitem,sum;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){scanf(%d,&n);/*---------*/sum=0;flag=1;item=0;t=1;for(i=1;i=n;i++){item=flag*1.0/t;sum=sum+item;flag=-flag;t=t+3;}printf(sum=%.3f\n,sum);}}20036程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:读入2个整数lower和upper,输出一张华氏—摄氏温度转换表,华氏温度的取值范围是[lower,upper],每次增加2F。计算公式:c=5*(f-32)/9,其中:c表示摄氏温度,f表示华氏温度。输出请使用语句printf(%3.0f%6.1f\n,fahr,celsius);输入输出示例:括号内是说明输入2(repeat=2)3235(lower=32,upper=35)4030(lower=40,upper=30)输出fahrcelsius320.0341.1fahrcelsius#includestdio.hintmain(void){intlower,upper;intrepeat,ri;doublecelsius,fahr;scanf(%d,&repeat);for(ri=1;ri=repeat;ri++){scanf(%d%d,&lower,&upper);printf(fahrcelsius\n);/*---------*/for(fahr=lower;fahr=upper;fahr=fahr+2){celsius=5*(fahr-32)/9;printf(%3.0f%6.1f\n,fahr,celsius);}}}20037程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(0repeat10),做repeat次下列运算:输入2个正整数m和n,计算m!+n!。输入输出示例:括号内是说明输入:2(repeat=2)14(m=1,n=4)38(m=3,n=8)输出:1!+4!=253!+8!=40326#includestdio.hintmain(void){inti,m,n;intrepeat,ri;doublefm,fn;sca