全国计算机二级C语言操作题题库.docx
《全国计算机二级C语言操作题题库.docx》由会员分享,可在线阅读,更多相关《全国计算机二级C语言操作题题库.docx(27页珍藏版)》请在冰豆网上搜索。
全国计算机二级C语言操作题题库
1.程序Cmody021.c输出如下所示图形:
*
*****
*******
*********
#include
voidmain()
{
inti,j;for(i=1;i<=5;i++)
for(j=1;j<=5-i;j++)printf("");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");
}
2.程序Cmody032.c的功能是:
输出201-300之间的所有素数,统计总个数。
intnum;
num=fun();
printf("\nThetotalofprimeis%d",num);
getch();
intfun()
intm,i,k,n=0;
for(m=201;m<=300;m++)
k=sqrt(m+1);
for(i=2;i<=k;i++)
/**/if(m/i==0)/**/
break;
/**/if(i==k)/**/
printf("%-4d",m);
n++;
if(n%10==0)printf("\n");
returnn;
3.
程序Cmody041.c,其功能是统计输入字符串中小写英文字母的个数。
如输入:
abcdEFGHIJK123
输出:
4
main()
charstr1[128];
/**/inti,len,sum=O;/**/
gets(str1);
len=strlen(str1);
for(i=0;i{/**/if(str1[i]>='a'&&str1[i]<='z')/**/sum++;}printf("%d\n",sum);getch();}3.程序Cmody051.c,其功能是统计输入字符串中大写英文字母的个数。如输入:abcDEFGH123输出:5#include#includemain(){/**/charstr1[128]/**/inti,len,sum=0;printf("Pleaseinputastring:\n");scanf("%s",str1);len=strlen(str1);for(i=0;i{if(str1[i]>='A'&&str1[i]<='Z')/**/sum++;/**/}printf("%d\n",sum);getch();}4.1的数字字符,将程序Cmody061.c,其功能是将字符串中’O'-8的数字字符变为比它大9变为'0'。如输入:abc12cd56EF89GH4输出:abc23cd67EF90GH5#include#includemain(){charstr1[128],str2[128];inti,len;gets(str1);len=strlen(str1);/**/for(i=0;i{if(str1[i]>='0'&&str1[i]<=8)str2[i]=str1[i]+1;elseif(str1[i]=='9')str2[i]='O:elsestr2[i]=str1[i];}/**/str2[i]='\n';/**/puts(str2);getch();}5.程序Cmody091.C,其功能是计算1至100之间的奇数之和,偶数之和。#includevoidmain(){intb,i;/**/inta=c=0;/**//**/for(i=0,i<=100,i+=2)/**/{a+=i;b=i+1;c+=b;}printf("totalofevennumbers:%d\n",a);printf("totalofoddnumbers:%d\n",c-101);getch();6.程序CmodylOl.c,其功能是计算如下所示的数学表达式:222a2.3a5.6b2.3b5.6c2.3c5.6sa8.2b8.2c8.2#include#defineF(x)(x*x-2.3*x+5.6)/(x+8.2)voidmain(){floata=6.0,b=3.0,c;/**/floats;/**/printf("\nPleaseinputc:");scanf("%f",/**/&c/**/);/**/s=F(a)+F(b)-F(c));/**/printf("\ns=%.2f\n,s");getch();}7.程序Cmody111.C,输出如下所示图形:@@@@@@@@@@@@@@@@@@@@@#include#includevoidmain(){/**/inti,j;/**//**/for(i=6;i>=1;i--)/**/{printf("@");for(j=1;j<=6_i;j++)printf("@");printf(/**/"\r"/**/);}getch();}8.打开Cprog011.C,完成其中的函数fun1,该函数的数学表达式是:Xfun1x1sinxe#inelude#includedoublefun1(doublex){Return((1+sin(x)+exp(x))/(x+1));}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开Cprog021.C,完成其中的函数fun1,该函数的数学表达式是:exlx6fun1x!x1.3例如:fun1(0.76)=3.582fun1(3.00)=5.369fun1(3.76)=8.931#include#includedoublefun1(doublex){Return((exp(x)+fabs(x-6))/(x+1.3));}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开Cprog031.C,完成其中的函数fun1,该函数的数学表达式是:1.2,x3fun1x10,x32x1,x3例如:fun1(0.76)=1.200fun1(3.00)=10.000fun1(3.76)=8.520Cprog031.C#inelude#includedoublefun1(doublex){lf(x<3)x=1.2;Elseif(x=3)x=10;Elsex=2*x+1;Return(x);}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开程序Cprog041.C,完成其中fun()函数,使其计算:0,x0fxlx3.2x0sinx2如输入:12输出f(12.000)=10.387输入:32.25输出f(32.250)=12.935输入:0.113输出f(0.113)=1568Cprog041.C#include#includedoublef(floatx){/**/x=0;rerurn((sqrt(x)+3.2)/(sin(x)+2))Return(x);If(x<=0)return(0);Elsex=(sqrt(x)+3.2)/(sin(x)+2);}voidmain(){floatx;doubley;printf("Pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%.3f)=%.3f\n",x,y);geteh();}1•打开程序Cprog051.C,完成其中的f()函数,使其计算:J5.8|xf,x700;fxeosx2.11,x700.如输入:0.4输出:f(0.40)=0.82输入:1.5输出:f(1.50)=1.24输入:7.80输出:f(780.00)=-1.00Cprog051.C#include#ineludedoublef(floatx){x=(sqrt(5.8+fabs(x))/(cos(x)+2.1));If(x>=-700&&x<=700)Elsex=-1;Return(x);}voidmain(){floatx;doubley;printf("pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%0.2f)=%0.2f\n",x,y);getehar();}1•打开程序Cprog061.C,完成其中的f()函数,使其计算:3xx300fxlg|x2.6,1,x300如输入:0.8输出:f(0.80)=0.96输入:4.5输出;f(4.50)=107.05输入;725输出;f(725.00)=-1.00Cprog061.C#include#includedoublef(floatx){return((x*x*x)/log10(fabs(x)+2.6));lf(x<=300&&x>=-300)Elsereturn(-1);}voidmain(){floatx;doubley;printf("Pleaseiuputanumber:\n");scanf("%f",&x);y=f(x);printf("f(%0.2f)=%0.2f\n",x,y);getch();}1•打开程序Cprog071.C,完成其中的f(x)的函数,使对其输入的一个月工资数额,求应交税款。设应交税款的计算公式如下:0,x1600;fVx16005%,1600x2100;Txx160010%25,2100x3100;x160015%125,x3100.例如输入:1825输出:f(1825)=11.25输入:2700输出:f(2700)=85.00输入:5655输出:f(5655)=483.25Cprog071.C#include#includedoublef(floatx){/**/lf(x<=1600)x=0;Elseif(x>1600&&x<=2100)x=(x-1600)*5%;Elseif(x>2100&&x<=3100)x=(x-1600)*10%-25;Elsex=(x-1600)*15%-125;Return(x);}voidmain(){floatx;doubley;clrscr();printf("Pleaseinputanumber:\n");scanf("%f",&x);y=f(x);printf("f(%.2f)=%.2f\n",x,y);getch();}打开程序Cprog081.C,完成其中的f(x)函数,使其计算:f(x)x2ex,x0;x2ln2x,x0.如输入:-1.2输出:f(-1.200)=0.241输入:6输出:f(6.000)=19.879Cprog081.C#include#includedoublef(floatx){If(x<=0)return((x+2)*exp(x));Elsereturn((x+2)*log(2*x));}voidmain(){floatx;doubley;printf("Pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%.3f)=%.3f\n",x,y);geteh();}bxe0的1•打开程序CPROG091,完成其中的f()函数,使其返回方程ax2两个根中较大的根,求根公式为x12―———4aC,其中假设:a0且b24ae02aCPROG091.C#include#ineludedoublef(floata,floatb,floate){/**/Doublex1,x2;x1=(-b+sqrt(b*b-4*a*c))/(2*a);X2=(-b-sqrt(b*b-4*a*c))/(2*a);If(x1>x2)return(x1);Elsereturn(x2);/**/}voidmain(){floatx;printf("Thebiggerrootis%.2f\n",f(1,5,6));geteh();}打开考生文件夹中的Cprog111.e,完成其中的函数fun,该表达式是1,Pnxx,例如:当x5.2,n6时,函数的值为4.724444。该函数返回数组a中的次大数(即仅次于最大数的数)Cprog111.c#includevoidmain(){doublex;intn;doublefun(doublex,intn);printf("Pleaseenterx,n:");scanf("%lf%d",&x,&n);printf("fun=%lf\n",fun(x,n));getch();}doublefun(doublex,intn){/**/doubleyIf(n==0)y=1;Elseif(n==1)y=x;Elseif(n>1)y=(2n-1)*x-fun(x,n-1)-(n-1)fun(x,n-2)/nReturn(y)}补充程序Ccon0112.C,其功能是求下列级数的部分和。#includemain(){inti,m;floatx,s,tem;scanf("%d,%f",&m,&x);/**/tem=1;s=1;/**/for(i=1;/**/i<=m/**/;i++){tem*=x/i;s+=tem;}printf("e**%.2f=%f\n",x,s);getch();}1.补充程序CconO91.C,输入一个3行3列的整型数组,求其最大值和最小值。如输入:123456789输出:max=9min=1CconO91.C#include"stdio.h"#defineROW3#defineCOL3voidmain(){inta[ROW][COL],i,j,max,min;for(i=0;i/**/max=min=a[0][0];/**/for(i=0;i{if(/**/a[i][j]>max/**/)max=a[i][j];if(a[i][j]/**/min=a[i][j];/**/}printf("max=%d\n",max);printf("min=%d\n",min);}程序CmodyOll.c的功能是:从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。例如,若str1所指的字符串为:4AZ18c?Ge9a0z!则t所指的字符为:4Z8z注意:数组下标从0开始。#include#include#include#includevoidmain(){charstr1[100],t[200];inti,j;/**/i=0;j=0;/**/strcpy(str1,"4AZ18c?Ge9a0z!");for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
/**/if(str1[i]>='a'&&str1[i]<='z')/**/
sum++;
printf("%d\n",sum);
3.程序Cmody051.c,其功能是统计输入字符串中大写英文字母的个数。
abcDEFGH123
输出:
5
/**/charstr1[128]/**/
inti,len,sum=0;
printf("Pleaseinputastring:
\n");
scanf("%s",str1);
for(i=0;i{if(str1[i]>='A'&&str1[i]<='Z')/**/sum++;/**/}printf("%d\n",sum);getch();}4.1的数字字符,将程序Cmody061.c,其功能是将字符串中’O'-8的数字字符变为比它大9变为'0'。如输入:abc12cd56EF89GH4输出:abc23cd67EF90GH5#include#includemain(){charstr1[128],str2[128];inti,len;gets(str1);len=strlen(str1);/**/for(i=0;i{if(str1[i]>='0'&&str1[i]<=8)str2[i]=str1[i]+1;elseif(str1[i]=='9')str2[i]='O:elsestr2[i]=str1[i];}/**/str2[i]='\n';/**/puts(str2);getch();}5.程序Cmody091.C,其功能是计算1至100之间的奇数之和,偶数之和。#includevoidmain(){intb,i;/**/inta=c=0;/**//**/for(i=0,i<=100,i+=2)/**/{a+=i;b=i+1;c+=b;}printf("totalofevennumbers:%d\n",a);printf("totalofoddnumbers:%d\n",c-101);getch();6.程序CmodylOl.c,其功能是计算如下所示的数学表达式:222a2.3a5.6b2.3b5.6c2.3c5.6sa8.2b8.2c8.2#include#defineF(x)(x*x-2.3*x+5.6)/(x+8.2)voidmain(){floata=6.0,b=3.0,c;/**/floats;/**/printf("\nPleaseinputc:");scanf("%f",/**/&c/**/);/**/s=F(a)+F(b)-F(c));/**/printf("\ns=%.2f\n,s");getch();}7.程序Cmody111.C,输出如下所示图形:@@@@@@@@@@@@@@@@@@@@@#include#includevoidmain(){/**/inti,j;/**//**/for(i=6;i>=1;i--)/**/{printf("@");for(j=1;j<=6_i;j++)printf("@");printf(/**/"\r"/**/);}getch();}8.打开Cprog011.C,完成其中的函数fun1,该函数的数学表达式是:Xfun1x1sinxe#inelude#includedoublefun1(doublex){Return((1+sin(x)+exp(x))/(x+1));}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开Cprog021.C,完成其中的函数fun1,该函数的数学表达式是:exlx6fun1x!x1.3例如:fun1(0.76)=3.582fun1(3.00)=5.369fun1(3.76)=8.931#include#includedoublefun1(doublex){Return((exp(x)+fabs(x-6))/(x+1.3));}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开Cprog031.C,完成其中的函数fun1,该函数的数学表达式是:1.2,x3fun1x10,x32x1,x3例如:fun1(0.76)=1.200fun1(3.00)=10.000fun1(3.76)=8.520Cprog031.C#inelude#includedoublefun1(doublex){lf(x<3)x=1.2;Elseif(x=3)x=10;Elsex=2*x+1;Return(x);}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开程序Cprog041.C,完成其中fun()函数,使其计算:0,x0fxlx3.2x0sinx2如输入:12输出f(12.000)=10.387输入:32.25输出f(32.250)=12.935输入:0.113输出f(0.113)=1568Cprog041.C#include#includedoublef(floatx){/**/x=0;rerurn((sqrt(x)+3.2)/(sin(x)+2))Return(x);If(x<=0)return(0);Elsex=(sqrt(x)+3.2)/(sin(x)+2);}voidmain(){floatx;doubley;printf("Pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%.3f)=%.3f\n",x,y);geteh();}1•打开程序Cprog051.C,完成其中的f()函数,使其计算:J5.8|xf,x700;fxeosx2.11,x700.如输入:0.4输出:f(0.40)=0.82输入:1.5输出:f(1.50)=1.24输入:7.80输出:f(780.00)=-1.00Cprog051.C#include#ineludedoublef(floatx){x=(sqrt(5.8+fabs(x))/(cos(x)+2.1));If(x>=-700&&x<=700)Elsex=-1;Return(x);}voidmain(){floatx;doubley;printf("pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%0.2f)=%0.2f\n",x,y);getehar();}1•打开程序Cprog061.C,完成其中的f()函数,使其计算:3xx300fxlg|x2.6,1,x300如输入:0.8输出:f(0.80)=0.96输入:4.5输出;f(4.50)=107.05输入;725输出;f(725.00)=-1.00Cprog061.C#include#includedoublef(floatx){return((x*x*x)/log10(fabs(x)+2.6));lf(x<=300&&x>=-300)Elsereturn(-1);}voidmain(){floatx;doubley;printf("Pleaseiuputanumber:\n");scanf("%f",&x);y=f(x);printf("f(%0.2f)=%0.2f\n",x,y);getch();}1•打开程序Cprog071.C,完成其中的f(x)的函数,使对其输入的一个月工资数额,求应交税款。设应交税款的计算公式如下:0,x1600;fVx16005%,1600x2100;Txx160010%25,2100x3100;x160015%125,x3100.例如输入:1825输出:f(1825)=11.25输入:2700输出:f(2700)=85.00输入:5655输出:f(5655)=483.25Cprog071.C#include#includedoublef(floatx){/**/lf(x<=1600)x=0;Elseif(x>1600&&x<=2100)x=(x-1600)*5%;Elseif(x>2100&&x<=3100)x=(x-1600)*10%-25;Elsex=(x-1600)*15%-125;Return(x);}voidmain(){floatx;doubley;clrscr();printf("Pleaseinputanumber:\n");scanf("%f",&x);y=f(x);printf("f(%.2f)=%.2f\n",x,y);getch();}打开程序Cprog081.C,完成其中的f(x)函数,使其计算:f(x)x2ex,x0;x2ln2x,x0.如输入:-1.2输出:f(-1.200)=0.241输入:6输出:f(6.000)=19.879Cprog081.C#include#includedoublef(floatx){If(x<=0)return((x+2)*exp(x));Elsereturn((x+2)*log(2*x));}voidmain(){floatx;doubley;printf("Pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%.3f)=%.3f\n",x,y);geteh();}bxe0的1•打开程序CPROG091,完成其中的f()函数,使其返回方程ax2两个根中较大的根,求根公式为x12―———4aC,其中假设:a0且b24ae02aCPROG091.C#include#ineludedoublef(floata,floatb,floate){/**/Doublex1,x2;x1=(-b+sqrt(b*b-4*a*c))/(2*a);X2=(-b-sqrt(b*b-4*a*c))/(2*a);If(x1>x2)return(x1);Elsereturn(x2);/**/}voidmain(){floatx;printf("Thebiggerrootis%.2f\n",f(1,5,6));geteh();}打开考生文件夹中的Cprog111.e,完成其中的函数fun,该表达式是1,Pnxx,例如:当x5.2,n6时,函数的值为4.724444。该函数返回数组a中的次大数(即仅次于最大数的数)Cprog111.c#includevoidmain(){doublex;intn;doublefun(doublex,intn);printf("Pleaseenterx,n:");scanf("%lf%d",&x,&n);printf("fun=%lf\n",fun(x,n));getch();}doublefun(doublex,intn){/**/doubleyIf(n==0)y=1;Elseif(n==1)y=x;Elseif(n>1)y=(2n-1)*x-fun(x,n-1)-(n-1)fun(x,n-2)/nReturn(y)}补充程序Ccon0112.C,其功能是求下列级数的部分和。#includemain(){inti,m;floatx,s,tem;scanf("%d,%f",&m,&x);/**/tem=1;s=1;/**/for(i=1;/**/i<=m/**/;i++){tem*=x/i;s+=tem;}printf("e**%.2f=%f\n",x,s);getch();}1.补充程序CconO91.C,输入一个3行3列的整型数组,求其最大值和最小值。如输入:123456789输出:max=9min=1CconO91.C#include"stdio.h"#defineROW3#defineCOL3voidmain(){inta[ROW][COL],i,j,max,min;for(i=0;i/**/max=min=a[0][0];/**/for(i=0;i{if(/**/a[i][j]>max/**/)max=a[i][j];if(a[i][j]/**/min=a[i][j];/**/}printf("max=%d\n",max);printf("min=%d\n",min);}程序CmodyOll.c的功能是:从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。例如,若str1所指的字符串为:4AZ18c?Ge9a0z!则t所指的字符为:4Z8z注意:数组下标从0开始。#include#include#include#includevoidmain(){charstr1[100],t[200];inti,j;/**/i=0;j=0;/**/strcpy(str1,"4AZ18c?Ge9a0z!");for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
if(str1[i]>='A'&&str1[i]<='Z')
/**/sum++;/**/
4.
1的数字字符,将
程序Cmody061.c,其功能是将字符串中’O'-8的数字字符变为比它大
9变为'0'。
abc12cd56EF89GH4
abc23cd67EF90GH5
charstr1[128],str2[128];
inti,len;
/**/for(i=0;i{if(str1[i]>='0'&&str1[i]<=8)str2[i]=str1[i]+1;elseif(str1[i]=='9')str2[i]='O:elsestr2[i]=str1[i];}/**/str2[i]='\n';/**/puts(str2);getch();}5.程序Cmody091.C,其功能是计算1至100之间的奇数之和,偶数之和。#includevoidmain(){intb,i;/**/inta=c=0;/**//**/for(i=0,i<=100,i+=2)/**/{a+=i;b=i+1;c+=b;}printf("totalofevennumbers:%d\n",a);printf("totalofoddnumbers:%d\n",c-101);getch();6.程序CmodylOl.c,其功能是计算如下所示的数学表达式:222a2.3a5.6b2.3b5.6c2.3c5.6sa8.2b8.2c8.2#include#defineF(x)(x*x-2.3*x+5.6)/(x+8.2)voidmain(){floata=6.0,b=3.0,c;/**/floats;/**/printf("\nPleaseinputc:");scanf("%f",/**/&c/**/);/**/s=F(a)+F(b)-F(c));/**/printf("\ns=%.2f\n,s");getch();}7.程序Cmody111.C,输出如下所示图形:@@@@@@@@@@@@@@@@@@@@@#include#includevoidmain(){/**/inti,j;/**//**/for(i=6;i>=1;i--)/**/{printf("@");for(j=1;j<=6_i;j++)printf("@");printf(/**/"\r"/**/);}getch();}8.打开Cprog011.C,完成其中的函数fun1,该函数的数学表达式是:Xfun1x1sinxe#inelude#includedoublefun1(doublex){Return((1+sin(x)+exp(x))/(x+1));}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开Cprog021.C,完成其中的函数fun1,该函数的数学表达式是:exlx6fun1x!x1.3例如:fun1(0.76)=3.582fun1(3.00)=5.369fun1(3.76)=8.931#include#includedoublefun1(doublex){Return((exp(x)+fabs(x-6))/(x+1.3));}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开Cprog031.C,完成其中的函数fun1,该函数的数学表达式是:1.2,x3fun1x10,x32x1,x3例如:fun1(0.76)=1.200fun1(3.00)=10.000fun1(3.76)=8.520Cprog031.C#inelude#includedoublefun1(doublex){lf(x<3)x=1.2;Elseif(x=3)x=10;Elsex=2*x+1;Return(x);}voidmain(){clrscr();printf("fun1(0.76)=%8.3lf\n",fun1(0.76));printf("fun1(3.00)=%8.3lf\n",fun1(3.00));printf("fun1(3.76)=%8.3lf\n",fun1(3.76));}打开程序Cprog041.C,完成其中fun()函数,使其计算:0,x0fxlx3.2x0sinx2如输入:12输出f(12.000)=10.387输入:32.25输出f(32.250)=12.935输入:0.113输出f(0.113)=1568Cprog041.C#include#includedoublef(floatx){/**/x=0;rerurn((sqrt(x)+3.2)/(sin(x)+2))Return(x);If(x<=0)return(0);Elsex=(sqrt(x)+3.2)/(sin(x)+2);}voidmain(){floatx;doubley;printf("Pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%.3f)=%.3f\n",x,y);geteh();}1•打开程序Cprog051.C,完成其中的f()函数,使其计算:J5.8|xf,x700;fxeosx2.11,x700.如输入:0.4输出:f(0.40)=0.82输入:1.5输出:f(1.50)=1.24输入:7.80输出:f(780.00)=-1.00Cprog051.C#include#ineludedoublef(floatx){x=(sqrt(5.8+fabs(x))/(cos(x)+2.1));If(x>=-700&&x<=700)Elsex=-1;Return(x);}voidmain(){floatx;doubley;printf("pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%0.2f)=%0.2f\n",x,y);getehar();}1•打开程序Cprog061.C,完成其中的f()函数,使其计算:3xx300fxlg|x2.6,1,x300如输入:0.8输出:f(0.80)=0.96输入:4.5输出;f(4.50)=107.05输入;725输出;f(725.00)=-1.00Cprog061.C#include#includedoublef(floatx){return((x*x*x)/log10(fabs(x)+2.6));lf(x<=300&&x>=-300)Elsereturn(-1);}voidmain(){floatx;doubley;printf("Pleaseiuputanumber:\n");scanf("%f",&x);y=f(x);printf("f(%0.2f)=%0.2f\n",x,y);getch();}1•打开程序Cprog071.C,完成其中的f(x)的函数,使对其输入的一个月工资数额,求应交税款。设应交税款的计算公式如下:0,x1600;fVx16005%,1600x2100;Txx160010%25,2100x3100;x160015%125,x3100.例如输入:1825输出:f(1825)=11.25输入:2700输出:f(2700)=85.00输入:5655输出:f(5655)=483.25Cprog071.C#include#includedoublef(floatx){/**/lf(x<=1600)x=0;Elseif(x>1600&&x<=2100)x=(x-1600)*5%;Elseif(x>2100&&x<=3100)x=(x-1600)*10%-25;Elsex=(x-1600)*15%-125;Return(x);}voidmain(){floatx;doubley;clrscr();printf("Pleaseinputanumber:\n");scanf("%f",&x);y=f(x);printf("f(%.2f)=%.2f\n",x,y);getch();}打开程序Cprog081.C,完成其中的f(x)函数,使其计算:f(x)x2ex,x0;x2ln2x,x0.如输入:-1.2输出:f(-1.200)=0.241输入:6输出:f(6.000)=19.879Cprog081.C#include#includedoublef(floatx){If(x<=0)return((x+2)*exp(x));Elsereturn((x+2)*log(2*x));}voidmain(){floatx;doubley;printf("Pleaseinputanumber:\n");seanf("%f",&x);y=f(x);printf("f(%.3f)=%.3f\n",x,y);geteh();}bxe0的1•打开程序CPROG091,完成其中的f()函数,使其返回方程ax2两个根中较大的根,求根公式为x12―———4aC,其中假设:a0且b24ae02aCPROG091.C#include#ineludedoublef(floata,floatb,floate){/**/Doublex1,x2;x1=(-b+sqrt(b*b-4*a*c))/(2*a);X2=(-b-sqrt(b*b-4*a*c))/(2*a);If(x1>x2)return(x1);Elsereturn(x2);/**/}voidmain(){floatx;printf("Thebiggerrootis%.2f\n",f(1,5,6));geteh();}打开考生文件夹中的Cprog111.e,完成其中的函数fun,该表达式是1,Pnxx,例如:当x5.2,n6时,函数的值为4.724444。该函数返回数组a中的次大数(即仅次于最大数的数)Cprog111.c#includevoidmain(){doublex;intn;doublefun(doublex,intn);printf("Pleaseenterx,n:");scanf("%lf%d",&x,&n);printf("fun=%lf\n",fun(x,n));getch();}doublefun(doublex,intn){/**/doubleyIf(n==0)y=1;Elseif(n==1)y=x;Elseif(n>1)y=(2n-1)*x-fun(x,n-1)-(n-1)fun(x,n-2)/nReturn(y)}补充程序Ccon0112.C,其功能是求下列级数的部分和。#includemain(){inti,m;floatx,s,tem;scanf("%d,%f",&m,&x);/**/tem=1;s=1;/**/for(i=1;/**/i<=m/**/;i++){tem*=x/i;s+=tem;}printf("e**%.2f=%f\n",x,s);getch();}1.补充程序CconO91.C,输入一个3行3列的整型数组,求其最大值和最小值。如输入:123456789输出:max=9min=1CconO91.C#include"stdio.h"#defineROW3#defineCOL3voidmain(){inta[ROW][COL],i,j,max,min;for(i=0;i/**/max=min=a[0][0];/**/for(i=0;i{if(/**/a[i][j]>max/**/)max=a[i][j];if(a[i][j]/**/min=a[i][j];/**/}printf("max=%d\n",max);printf("min=%d\n",min);}程序CmodyOll.c的功能是:从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。例如,若str1所指的字符串为:4AZ18c?Ge9a0z!则t所指的字符为:4Z8z注意:数组下标从0开始。#include#include#include#includevoidmain(){charstr1[100],t[200];inti,j;/**/i=0;j=0;/**/strcpy(str1,"4AZ18c?Ge9a0z!");for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
if(str1[i]>='0'&&str1[i]<=8)
str2[i]=str1[i]+1;
elseif(str1[i]=='9')
str2[i]='O:
elsestr2[i]=str1[i];
/**/str2[i]='\n';/**/
puts(str2);
5.程序Cmody091.C,其功能是计算1至100之间的奇数之和,偶数之和。
intb,i;
/**/inta=c=0;/**/
/**/for(i=0,i<=100,i+=2)/**/
a+=i;
b=i+1;
c+=b;
printf("totalofevennumbers:
%d\n",a);
printf("totalofoddnumbers:
%d\n",c-101);getch();
6.程序CmodylOl.c,其功能是计算如下所示的数学表达式:
222
a2.3a5.6b2.3b5.6c2.3c5.6
s
a8.2b8.2c8.2
#defineF(x)(x*x-2.3*x+5.6)/(x+8.2)
floata=6.0,b=3.0,c;
/**/floats;/**/
printf("\nPleaseinputc:
");
scanf("%f",/**/&c/**/);
/**/s=F(a)+F(b)-F(c));/**/
printf("\ns=%.2f\n,s");
7.程序Cmody111.C,输出如下所示图形:
@
@@
@@@
@@@@
@@@@@
@@@@@@
/**/inti,j;/**/
/**/for(i=6;i>=1;i--)/**/
printf("@");
for(j=1;j<=6_i;j++)
printf(/**/"\r"/**/);
8.打开Cprog011.C,完成其中的函数fun1,该函数的数学表达式是:
X
fun1x
1sinxe
#inelude
doublefun1(doublex)
Return((1+sin(x)+exp(x))/(x+1));
clrscr();
printf("fun1(0.76)=%8.3lf\n",fun1(0.76));
printf("fun1(3.00)=%8.3lf\n",fun1(3.00));
printf("fun1(3.76)=%8.3lf\n",fun1(3.76));
打开Cprog021.C,完成其中的函数fun1,该函数的数学表达式是:
exlx6
fun1x!
x1.3
例如:
fun1(0.76)=3.582
fun1(3.00)=5.369
fun1(3.76)=8.931
Return((exp(x)+fabs(x-6))/(x+1.3));
打开Cprog031.C,完成其中的函数fun1,该函数的数学表达式是:
1.2,
x3
10,
2x1,
fun1(0.76)=1.200fun1(3.00)=10.000fun1(3.76)=8.520
Cprog031.C
lf(x<3)x=1.2;
Elseif(x=3)x=10;
Elsex=2*x+1;
Return(x);
打开程序Cprog041.C,完成其中fun()函数,使其计算:
0,x0
fxlx3.2
x0
sinx2
12输出f(12.000)=10.387输入:
32.25输出f(32.250)=12.935
输入:
0.113输出f(0.113)=1568
Cprog041.C
#includedoublef(floatx){
/**/
x=0;
rerurn((sqrt(x)+3.2)/(sin(x)+2))
If(x<=0)return(0);
Else
x=(sqrt(x)+3.2)/(sin(x)+2);
floatx;
doubley;
printf("Pleaseinputanumber:
seanf("%f",&x);
y=f(x);
printf("f(%.3f)=%.3f\n",x,y);
geteh();
1•打开程序Cprog051.C,完成其中的f()函数,使其计算:
J5.8|x
f,x700;
fxeosx2.1
1,x700.
0.4输出:
f(0.40)=0.82
1.5输出:
f(1.50)=1.24
7.80输出:
f(780.00)=-1.00
Cprog051.C#include#ineludedoublef(floatx){
x=(sqrt(5.8+fabs(x))/(cos(x)+2.1));
If(x>=-700&&x<=700)
Elsex=-1;
printf("pleaseinputanumber:
\n");seanf("%f",&x);
printf("f(%0.2f)=%0.2f\n",x,y);getehar();
1•打开程序Cprog061.C,完成其中的f()函数,使其计算:
3x
x300
fx
lg|x
2.6,
1,
x
300
0.8
f(0.80)=0.96
4.5
输出;
f(4.50)=107.05
输入;
725
f(725.00)=-1.00
Cprog061.C
#include#includedoublef(floatx){
return((x*x*x)/log10(fabs(x)+2.6));
lf(x<=300&&x>=-300)Elsereturn(-1);
printf("Pleaseiuputanumber:
scanf("%f",&x);
printf("f(%0.2f)=%0.2f\n",x,y);
1•打开程序Cprog071.C,完成其中的f(x)的函数,使对其输入的一个月工资数
额,
求应交税款。
设应交税款的计算公式如下:
0,
x1600;
fV
1600
5%,
1600x
2100;
Tx
10%
25,2100x
3100;
15%
125,x3100.
例如
1825
输出
:
f(1825)=11.25
2700
f(2700)=85.00
5655
f(5655)=483.25
Cprog071.C
doublef(floatx)
lf(x<=1600)x=0;
Elseif(x>1600&&x<=2100)x=(x-1600)*5%;
Elseif(x>2100&&x<=3100)x=(x-1600)*10%-25;
Elsex=(x-1600)*15%-125;
printf("f(%.2f)=%.2f\n",x,y);
打开程序Cprog081.C,完成其中的f(x)函数,使其计算:
f(x)x2ex,x0;
x2ln2x,x0.
-1.2输出:
f(-1.200)=0.241
6输出:
f(6.000)=19.879
Cprog081.C
If(x<=0)return((x+2)*exp(x));
Elsereturn((x+2)*log(2*x));
bxe0的
1•打开程序CPROG091,完成其中的f()函数,使其返回方程ax2
两个根中较大的根,求根公式为
x12―———4aC,其中假设:
a0且b24ae0
2a
CPROG091.C
#ineludedoublef(floata,floatb,floate){
Doublex1,x2;x1=(-b+sqrt(b*b-4*a*c))/(2*a);X2=(-b-sqrt(b*b-4*a*c))/(2*a);If(x1>x2)return(x1);
Elsereturn(x2);
/**/}
printf("Thebiggerrootis%.2f\n",f(1,5,6));geteh();
打开考生文件夹中的Cprog111.e,完成其中的函数fun,该表达式是
Pnxx,
当x5.2,n6时,函数的值为4.724444。
该函数返回数组a中的次大数(即仅次于最大数的数)
Cprog111.c
doublex;
intn;
doublefun(doublex,intn);
printf("Pleaseenterx,n:
scanf("%lf%d",&x,&n);
printf("fun=%lf\n",fun(x,n));
doublefun(doublex,intn)
/**/doubley
If(n==0)y=1;
Elseif(n==1)y=x;
Elseif(n>1)y=(2n-1)*x-fun(x,n-1)-(n-1)fun(x,n-2)/nReturn(y)
补充程序Ccon0112.C,其功能是求下列级数的部分和。
inti,m;
floatx,s,tem;
scanf("%d,%f",&m,&x);
/**/tem=1;s=1;/**/
for(i=1;/**/i<=m/**/;i++)
tem*=x/i;
s+=tem;
printf("e**%.2f=%f\n",x,s);
1.补充程序CconO91.C,输入一个3行3列的整型数组,求其最大值和最小值。
123
456
789
max=9
min=1
CconO91.C
#include"stdio.h"
#defineROW3
#defineCOL3
inta[ROW][COL],i,j,max,min;
for(i=0;i/**/max=min=a[0][0];/**/for(i=0;i{if(/**/a[i][j]>max/**/)max=a[i][j];if(a[i][j]/**/min=a[i][j];/**/}printf("max=%d\n",max);printf("min=%d\n",min);}程序CmodyOll.c的功能是:从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。例如,若str1所指的字符串为:4AZ18c?Ge9a0z!则t所指的字符为:4Z8z注意:数组下标从0开始。#include#include#include#includevoidmain(){charstr1[100],t[200];inti,j;/**/i=0;j=0;/**/strcpy(str1,"4AZ18c?Ge9a0z!");for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
/**/max=min=a[0][0];/**/
for(i=0;i{if(/**/a[i][j]>max/**/)max=a[i][j];if(a[i][j]/**/min=a[i][j];/**/}printf("max=%d\n",max);printf("min=%d\n",min);}程序CmodyOll.c的功能是:从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。例如,若str1所指的字符串为:4AZ18c?Ge9a0z!则t所指的字符为:4Z8z注意:数组下标从0开始。#include#include#include#includevoidmain(){charstr1[100],t[200];inti,j;/**/i=0;j=0;/**/strcpy(str1,"4AZ18c?Ge9a0z!");for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
if(/**/a[i][j]>max/**/)
max=a[i][j];
if(a[i][j]/**/min=a[i][j];/**/}printf("max=%d\n",max);printf("min=%d\n",min);}程序CmodyOll.c的功能是:从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。例如,若str1所指的字符串为:4AZ18c?Ge9a0z!则t所指的字符为:4Z8z注意:数组下标从0开始。#include#include#include#includevoidmain(){charstr1[100],t[200];inti,j;/**/i=0;j=0;/**/strcpy(str1,"4AZ18c?Ge9a0z!");for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
/**/min=a[i][j];/**/
}printf("max=%d\n",max);
printf("min=%d\n",min);
程序CmodyOll.c的功能是:
从字符串数组strl中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。
例如,若str1所指的字符串为:
4AZ18c?
Ge9a0z!
则t所指的字符为:
4Z8z
注意:
数组下标从0开始。
charstr1[100],t[200];
inti,j;
/**/i=0;j=0;/**/
strcpy(str1,"4AZ18c?
for(i=0;i{/**/if((str1[i]%2==0)&&(i%2==0))/**/{t[j]=str1[i];j++;}}t[j]='\0';printf("\nOriginalstring:%s\n",str1);printf("\nResultstring:%s\n",t);}程序Cmody012.c中,函数fun(intn)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。#include#include#include#include#defineM50doublefun(intn){doubley=0.0;inti,j;j=0;for(i=1;;i++){/**/if((i>10)&&(i%3==0))/**/{/**/y+=1/i;/**/j++;}if(j==n)break;}returny;}voidmain(){clrscr();printf("fun(8)=%8.3lf\n",fun(8));}.程序Cmody022.c的功能是求解百元买百鸡问题:设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?#include#include/*doublefun();/**/{inthen,cock,chicken,n=0;clrscr();for(cock=0;cock<=50;cock+=1)for(hen=0;hen<=100;hen=hen+1){chicken=2*(100-hen-2*cock);/**/if(cock+hen+chicken==100)/**/{n++;printf("%d-->hen:%d,cock:%d,chicken:%d\n”,n,hen,cock,chicken);if(n==20)getch();}}returnn;}voidmain(){intnum;num=fun();printf("\nThereare%dsolutions.\n",num);getch();}*、/或%),进1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符什、-行相应的运算后输出运算的结果。如输入:1+2将输出:1+2=3#include#includevoidmain(){intm,n,result,flag=0;/**/charch;/**/clrscr();printf("Inputanexpression:”);scanf("%d%c%d",&m,&ch,&n);/**/switch(ch)/**/{case'+':result=m+n;break;case'-':result=m-n;break;case'*':result=m*n;break;case'%':result=m%n;break;case'/':result=m/n;break;default:{printf("Error!\n");flag=1;}}if(!flag)printf("%d%c%d=%d\n",m,ch,n,result);getch();}
/**/if((str1[i]%2==0)&&(i%2==0))/**/
t[j]=str1[i];
j++;
t[j]='\0';
printf("\nOriginalstring:
%s\n",str1);
printf("\nResultstring:
%s\n",t);
程序Cmody012.c中,函数fun(intn)的功能是:
根据参数n,计算大于10的最小n个能被
3整除的正整数的倒数之和。
#defineM50
doublefun(intn)
doubley=0.0;
j=0;
for(i=1;;i++)
/**/if((i>10)&&(i%3==0))/**/
/**/y+=1/i;/**/
if(j==n)break;
returny;
printf("fun(8)=%8.3lf\n",fun(8));
.程序Cmody022.c的功能是求解百元买百鸡问题:
设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。
问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?
有多少种分配方案?
/*doublefun();/**/
inthen,cock,chicken,n=0;
for(cock=0;cock<=50;cock+=1)
for(hen=0;hen<=100;hen=hen+1)
chicken=2*(100-hen-2*cock);
/**/if(cock+hen+chicken==100)/**/
printf("%d-->hen:
%d,cock:
%d,chicken:
%d\n”,n,hen,cock,chicken);
if(n==20)getch();
printf("\nThereare%dsolutions.\n",num);
*、/或%),进
1.程序Cmody031.c的功能是:
从键盘上输入两个整数,及一个运算符什、-
行相应的运算后输出运算的结果。
1+2
将输出:
1+2=3
intm,n,result,flag=0;
/**/charch;/**/
printf("Inputanexpression:
”);
scanf("%d%c%d",&m,&ch,&n);
/**/switch(ch)/**/
case'+':
result=m+n;break;
case'-':
result=m-n;break;
case'*':
result=m*n;break;
case'%':
result=m%n;break;
case'/':
result=m/n;break;
default:
{printf("Error!
\n");flag=1;}
if(!
flag)printf("%d%c%d=%d\n",m,ch,n,result);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1