C语言考试大题答案.docx

上传人:b****5 文档编号:8019968 上传时间:2023-01-28 格式:DOCX 页数:23 大小:171.81KB
下载 相关 举报
C语言考试大题答案.docx_第1页
第1页 / 共23页
C语言考试大题答案.docx_第2页
第2页 / 共23页
C语言考试大题答案.docx_第3页
第3页 / 共23页
C语言考试大题答案.docx_第4页
第4页 / 共23页
C语言考试大题答案.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

C语言考试大题答案.docx

《C语言考试大题答案.docx》由会员分享,可在线阅读,更多相关《C语言考试大题答案.docx(23页珍藏版)》请在冰豆网上搜索。

C语言考试大题答案.docx

C语言考试大题答案

C20111225大题答案

#include

voidmain()

{longf=/**/1/**/;

inti;

for(i=1;i<=13;/**/i=i+2/**/)

f=f*i;

printf("\nf=%ld",f);

getch();

}

#include

voidmain()

{

intp,q,r;

floatf;

clrscr();

printf("Pleaseinputpq:

");

scanf("%d%d",/**/&p,&q/**/);

f=1.0*p/q;

r=(int)/**/f*10/**/%10;

printf("\np/q=%fThefirstdecimalplaceis:

%d\n",f,r);

getch();

}

#include

#include

doublef(double/**/x/**/)

{return(x*x*x+1.3*x*x+1.1*x-1.2);

}

voidmain()

{floatx,x1,x2;

doubley,y1,y2;

do

{printf("Inputx1,x2:

");

scanf("%f,%f",&x1,&x2);

y1=f(x1);

y2=f(x2);

}while(y1*y2>=0);

do

{x=(x1+x2)/2;

y=/**/f/**/(x);

y1=f(x1);

if(y*y1>0)

x1=x;

else

x2=/**/x/**/;

}while(fabs(y)>=1e-6);

printf("RootofEquationis%8.3f\n",x);

getch();

}

#include

#include

voidmain()

{

chars[20];

inti;

printf("Pleaseinputastring:

");

scanf(/**/“%s”/**/,s);

i=0;

while(s[i])

{

s[i]=/**/s[i]^3;/**/

/**/i++;/**/

}

printf("\nTargetstring:

%s\n",s);

getch();

}

#include

voidmain()

{inti,n;

/**/n=0/**/;

for(i=1;i<=/**/1000/**/;i++)

{if((i%3==0||i%7==0)&&(i%/**/10/**/==3))

{printf("%5d",i);

n++;

if(n%6==0)

printf("\n");

}

}

getch();

}

#include

#include

voidsort(inta[],intn)

{inti,j,k,temp;

for(i=0;i

{k=i;

for(/**/j=i+1/**/;j

if(/**/a[k]

if(k!

=i)

{temp=/**/a[k]/**/;

a[k]=a[i];

a[i]=temp;

}

}

}

voidmain()

{

inta[]={50,25,88,32,2,65,7,64};

inti,n=sizeof(a)/sizeof(int);

sort(a,n);

for(i=0;i

printf("%d",a[i]);

printf("\n");

getch();

}

#include

#include/**//**/

doublef(doublex)

{doubley;

y=/**/7.7*x*x+10.3*x+6.6/**/;

return(y);

}

voidmain()

{doublex,y1,y2;

printf("Pleaseinputx:

");

scanf("%lf",&x);

y1=f(/**/x+1.1/**/);

y2=f(sin(x));

printf("\nf(x+1.1)=%.3lf",y1);

printf("\nf(sinx)=%.3lf",y2);

getch();

}_

#include

#include

intcount(/**/chars[]/**/)

{

intn=0;

char*p=/**/s/**/;

while(*p)

{if(*p=='a')n++;

/**/p++/**/;

}

returnn;

}

voidmain()

{

chars[255];

printf("Enterastring:

");

gets(s);

printf("Countofais:

%d\n",count(s));

getch();

}

#include"stdio.h"

#defineROW3

#defineCOL4

voidmain()

{inta[ROW][COL]={2,11,3,5,7,24,8,9,16,10,18,66};

intb[ROW][COL]={1,9,5,12,6,11,13,2,15,7,25,56};

intc[/**/ROW/**/][COL],i,j;

for(i=0;i

for(j=0;j

c[i][j]=/**/a[i][j]-b[i][j];/**/

for(i=0;i

{for(j=0;j

printf("%5d",c[i][j]);

printf("\n");

}

getch();

}

#include

unsignedlongfun(unsignedlongn)

{

unsignedlongx=0;intt=0;

while(n)

{t=n%10;

if(t%2==/**/1/**/)

x=/**/10*x/**/+t;

n=n/10;

}

returnx;

}

voidmain()

{

unsignedlongn=-1;

while(n>99999999||n<0)

{

printf("Pleaseinput(0

");

scanf("%ld",&n);

}

printf("\nTheresultis:

%ld\n",fun(n));

getch();

}

#include

voidmain()

{inta,b,temp;

printf("a,b=");

scanf("%d,%d",&a,&b);

if(a

{temp=a;

a=b;

/**/temp=b;/**//*改:

b=temp;*/

}

while(--a>b)

{if(/**/(a%2)/**/)/*改:

(a%2)或改:

a%2==0*/

printf("%5d",a);

}

getch();

}

#include

/**/voidfun(intn)/**/改:

doublefun(intn)

{doubley=0.0;

inta=2,b=1,c,k;

for(k=1;k<=n;k++)

{/**/y+=(Double)a/b;/**/改:

y+=(double)a/b;

c=a;

/**/a=b/**/;改:

a=a+b

b=c;

}

returny;

}

voidmain()

{printf("fun(5)=%lf\n",fun(5));

getch();

}

#include

voidmain()

{/**/inta=10;num,mark;/**/改:

inta=10,num,mark;

charop,es;

printf("InputanExpression:

a");

scanf("%c%c%d",&op,&es,&num);

mark=0;

if(es=='=')

{/**/swich/**/(op)改:

switch

{case'+':

a=a+num;break;

case'-':

a=a-num;break;

case'*':

a=a*num;break;

case'/':

if(num)a=a/num;

elsemark=1;

break;

default:

mark=1;

}

}

else

mark=1;

if(!

mark)

printf("a=%d\n",a);

else

printf("Error!

\n");

getch();

}

#include

intfun(int*x,inty)

{intt;

t=*x;

/**/x=y;/**/改:

*x=*y;

/**/return(y);/**/改:

return(t);

}

voidmain()

{intx=6,y=8;

printf("%d,%d\n",x,y);

y=fun(&x,y);

printf("%d,%d\n",x,y);

getch();

}

#include

#include

voidmain()

{/**/characterstr[100];/**/改:

charstr[100];

intnumber,u_letter,l_letter,i;

number=u_letter=l_letter=0;

printf("Pleaseinputstring:

");

gets(str);

/**/i=1;/**/改:

i=0;

while(str[i])

{if(str[i]>='0'&&str[i]<='9')

number++;

/**/elseif(str[i]>='A'||str[i]<='M')/**/改:

elseif(str[i]>='A'&&str[i]<='M')

u_letter++;

elseif(str[i]>='n'&&str[i]<='z')

l_letter++;

i++;

}

printf("number=%d,u_letter=%d,l_letter=%d\n",number,u_letter,l_letter);

getch();

}

#include

#include

voidmain()

{chars[20]="international51",t[20];

chartab[5][2]={{'c','h'},{'i','a'},{'a','b'},{'e','g'},{'l','p'}};

inti,j=0;

/**/strcmp(t,s);/**/改:

strcpy(t,s);

while(t[j])

{for(i=0;/**/i<=3/**/;i++)改:

i<=5

if(t[j]==tab[i][0])

{/**/t[j]=tab[i];/**/改:

t[j]=tab[i][1];

break;

}

j++;

}

printf("\nThesourestring:

%s\n",s);

printf("\nThetargetstring:

%s\n",t);

getch();

}

#include

voidmain()

{/**/inti=1,n=1;/**/改:

inti=1,n=0;

do

{if(i%3==2&&/**/i%5=3/**/)改:

i%5==3

{printf("%5d",i);

n++;

if(!

(n%5))

printf("\n");

}

i++;

}/**/while(i<1000)/**/改:

while(i<1000);

getch();

}

#include

voidfun(char*p,char*b)

{inti,k=0;

while(*p)

{i=1;

while(i<=4&&*p)

{/**/b[k]=p;/**/改:

b[k]=*p;

k++;

p++;

i++;

}

if(*p)

{/**/b[k++]="";/**/改:

b[k++]=32;

}

}

b[k]='\0';

}

voidmain()

{chara[80],b[80];

printf("Enterastring:

");

gets(a);

printf("Theoriginalstring:

");

puts(a);

fun(a,b);

printf("\nThestringafterinsertspace:

");

puts(b);

printf("\n");

getch();

}

#include

voidmain()

{/**/intn,i,bk;/**/改:

intn,i,bk,j;

printf("Inputanum(1-9):

");

scanf("%d",&n);

for(i=1;i<=n;i++)

{for(bk=1;bk<=n;bk++)

printf("");

for(j=1;/**/j<=i+1/**/;j++)改:

j<=i

printf("%d",i);

printf("\n");

}

for(i=1;i<=n;i++)

{for(bk=1;bk<=i;bk++)

printf("");

for(j=1;j<=n-i+1;j++)

printf("%d",n-i+1);

printf(/**/"/n"/**/);

}

getch();

}

#include

voidmain()

{intr,m,n,p,q;

printf("Enterm,n:

");

scanf("%d,%d",&m,&n);

p=m;q=n;

/**/r=m/n;/**/改:

r=m%n;

while(/**/r==0/**/)改:

r或r!

=0

{m=n;

n=r;

r=m%n;

}

printf("gcd(%d,%d)=%d\n",p,q,n);

getch();

}

#include

#include

doublefun(doublex,doubley)

{/**/

return(7.7*x+6.9*y)/(fabs(2.3*y+1.3*x));

/**/

}

voidmain()

{printf("fun(1.1,0.2)=%6.3lf\n",fun(1.1,0.2));

getch();

}

#include

intfun(intx,inta[],intn,intb[],intc[])

{/**/

inti,k,nb=0,t;

for(i=0;i

if(a[i]>x){c[nb]=b[nb]=a[i];nb++;}

for(i=0;i

for(k=i+1;k

if(c[i]

returnnb;

/**/

}

voidmain()

{intn=10,i,x,nb;

intaa[10]={32,-5,-31,-10,25,50,12,15,-16,18};

intbb[10],cc[10];

clrscr();

printf("Pleaseinputx:

");

scanf("%d",&x);

printf("Countofarrayaa:

%3d\n",n);

printf("Elementofarrayaa:

");

for(i=0;i

printf("\n");

nb=fun(x,aa,n,bb,cc);

printf("Elementofarraybb:

");

for(i=0;i

printf("\n");

printf("Elementofarraycc:

");

for(i=0;i

printf("\n");

printf("Countofarraybb:

%3d\n",nb);

getch();

}

#include

#include

doublefun1(doublex)

{/**/

return(7.8-sin(x))/(exp(x)+0.3);

/**/

}

voidmain()

{printf("fun1(2.5)=%6.3lf\n",fun1(2.5));

getch();

}

#include

#include

voidfun(char*s,chart[])

{/**/

inti,j=0

for(i=0;s[i];i++)

if(i%2&&s[i]%2)t[j++]=s[i];

t[j]=’\0’;

/**/

}

voidmain()

{

chars[100],t[100];

printf("\nPleaseenterstrings:

");

scanf("%s",s);

fun(s,t);

printf("\nTheresultis:

%s\n",t);

getch();

}

#include

#include

doublefun(floatx)

{/**/

doubley;

if(x<2)y=fabs(1.02*x-1.36);

if(x==2)y=exp(x)+pow(x,3);

if(x>2)y=cos(x);

returny;

/**/

}

voidmain()

{floatx;

printf("Pleaseinputanumber:

");

scanf("%f",&x);

printf("fun(%.2f)=%.2lf\n",x,fun(x));

getch();

}

#include

#include

voidfun(inta,intb,long*c)

{/**/

intx1,x2,x3,x4;

x1=a/10;x2=a%10;

x3=b/10;x4=b%10;

*c=1000*x4+100*x2+10*x3+x1

/**/

}

voidmain()

{

inta,b;

longc;

printf("Inputa,b:

");

scanf("%d,%d",&a,&b);

fun(a,b,&c);

printf("Theresultis:

%ld",c);

getch();

}

#include

#include

doublefun(floatx)

{/**/

doubley;

if(x<5)y=fabs(x-5.6);

if(x==5)y=x;

if(x>5)y=x*x-10.2;

returny

/**/

}

voidmain()

{floatx;

printf("Pleaseinputanumber:

");

scanf("%f",&x);

printf("fun(%.2f)=%.2lf\n",x,fun(x));

getch();

}

#include

floatfun(intn)

{/**/

floats=0,p=0;

inti;

for(i=1;i<=n;i++)

{p+=2*i-1;

s+=i/p;

}

returns;

/**/

}

voidmain()

{

intn;

floats;

printf("Pleaseentern=");

scanf("%d",&n);

s=fun(n);

printf("\nTheresultis:

%.3f",s);

getch();

}

#include

#include

doublefun(doublex)

{/**/

doubley;

y=1.0/2*(2.3*x+(4.6-x)/(x+6.2));

returny;

/**/

}

voidmain()

{printf("fun(1.6)=%6.3lf\n",fun(1.6));

getch();

}

#include

#defineN3

voidfun(inta[N][N],intn)

{/**/

for(i=0;i

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 自然景观

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1