南昌大学C语言题目 综合练习.docx
《南昌大学C语言题目 综合练习.docx》由会员分享,可在线阅读,更多相关《南昌大学C语言题目 综合练习.docx(46页珍藏版)》请在冰豆网上搜索。
![南昌大学C语言题目 综合练习.docx](https://file1.bdocx.com/fileroot1/2023-1/31/d2bf85f1-f7a4-4a86-855f-9b4c49899c6e/d2bf85f1-f7a4-4a86-855f-9b4c49899c6e1.gif)
南昌大学C语言题目综合练习
一、阅读程序写出程序运行结果
阅读以下程序并写出其运行结果
#include
#include
intfun(chars[],intc)
{
char*q=s;
for(;*q;q++)
if(*q!
=c)*(s++)=*q;
*s=0;
}
main()
{
staticcharstr[]="turbocandborlandc++";
charch;
fun(str,'c');
printf("str[]=%s\n",str);
system("pause");
}
程序的运行结果是
str[]=turboandborlandc++
请按任意键继续...
阅读以下程序并写出其运行结果
#include
#include
voidfun(inta,intb,long*c)
{
*c=a/10*10+a%10*1000+b/10*100+b%10;
}
main()
{inta=42,b=25;longc;
fun(a,b,&c);
printf("Theresultis:
%ld\n",c);
system("pause");
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
voidfun(int*s,intnl,intn2)
{inti,j,t;
i=nl;j=n2;
while(i}
main()
{inta[10]={1,2,3,4,5,6,7,8,9,0},k;
fun(a,0,3);fun(a,4,9);fun(a,0,9);
for(k=0;k<10;k++)printf(“%d”,a[k]);printf(“\n”);
}
程序运行的结果是
阅读以下程序并写出其运行结果
#include
main()
{
inti=1;
while(!
((i%2==1)&&(i%3==2)&&(i%5==4)&&(i%6==5)&&(i%7==0)))
++i;
printf("\n>>Theladderhas%dstages.\n",i);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#defineROW3
#defineCOL4
main()
{
intmatrixA[ROW][COL]={11,12,13,14,15,16,17,18,19,20,21,22};
intmatrixB[COL][ROW];
inti,j;
printf("%d*%d:
\n",ROW,COL);
for(i=0;ifor(j=0;j
matrixB[j][i]=matrixA[i][j];
}
}
printf("MatrixB,");
printf("%d*%d:
\n",COL,ROW);
for(i=0;i
for(j=0;jprintf("%8d",matrixB[i][j]);
}
printf("\n");
}
system("pause");
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#defineN10
main()
{
intprimes[N];
intpc,m,k;
printf("\nThefirst%dprimenumbersare:
\n",N);
primes[0]=2;
pc=1;
m=3;
while(pc{
k=0;
while(primes[k]*primes[k]<=m)
if(m%primes[k]==0)
{
m+=2;
k=1;
}
else
k++;
primes[pc++]=m;
m+=2;
}
for(k=0;kprintf("%4d",primes[k]);
system("pause");
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#include
voidfun(char*s[],intn)
{char*t;
inti,j;
for(i=0;ifor(j=i+1;jif(strlen(s[i])>strlen(s[j])){t=s[i];s[i]=s[j];s[j]=t;}
}
main()
{char*ss[]={“bcc”,”bbcc”,”xy”,”aaaacc”,”aabcc”};
fun(ss,5);printf(“%s,%s\n”,ss[0],ss[4]);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
voidfun(char*a,char*b)
{while(*a==’*’)a++;
while(*b=*a){b++;a++;}
}
main()
{char*s=”****a*b****”,t[80];
fun(s,t);
puts(t);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
main()
{FILE*fp;
inta[10]={1,2,3},i,n;
fp=fopen(“dl.dat”,”w”);
for(i=0;i<3;i++)fprintf(fp,”%d”,a[i]);
fprintf(fp,”\n”);
fclose(fp);
fp=fopen(“dl.dat”,”r”);
fscanf(fp,”%d”,&n);
fclose(fp);
printf(“%d\n”,n);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
voidswap(int*a,int*b)
{int*t;
t=a;a=b;b=t;
}
main()
{inti=3,j=5,*p=&i,*q=&j;
swap(p,q);printf(“%d%d\n”,*p,*q);
}
程序的运行结果是
阅读以下程序并写出其运行结果
intcircle(intn,intd)
{
ints=0,m=n;
while(m)
{
s=s*d+m%d;
m/=d;
}
returns==n;
}
intnum[]={232,27,851};
intscale[]={2,10,16};
main()
{
inti,j;
for(i=0;ifor(j=0;jif(circle(num[i],scale[j]))
printf("%d->(%d)isaCircleNumber!
\n",num[i],scale[j]);
else
printf("%d->(%d)isnotaCircleNumber!
\n",num[i],scale[j]);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#defineNULL0
int*search2(int*pa,int*pb,intan,intbn)
{
int*ca,*cb;
ca=pa;cb=pb;
while(ca{
if(*ca<*cb)
ca++;
elseif(*ca>*cb)
cb++;
else
returnca;/*返回在这两个数表中找到相等元素*/
}
returnNULL;
}
main()
{
int*vp,i;
inta[]={1,3,5,7,9,13,15,27,29,37};
intb[]={2,4,6,8,10,13,14,27,29,37};
puts("Theelementsofarrayais:
");
for(i=0;iprintf("%d",a[i]);
puts("\nTheelementsofarraybis:
");
for(i=0;iprintf("%d",b[i]);
vp=search2(a,b,sizeofa/sizeofa[0],sizeofb/sizeofb[0]);
if(vp)printf("\nThefirstsamenumberinbotharraysis%d\n",*vp);
elseprintf("Notfound!
\n");
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
main()
{
inti,j;
charch;
i=1;
while(i<=5){
j=1;
ch='a';
while(j<=i){
printf("%2c",ch);
ch=ch+1;
j++;
}
printf("\n");
i++;
}
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
rest(inta[],intn)
{
inti,low,high,t;
for(i=0,low=0,high=n-1;i<=high;)
{
if(a[i]>0)
{
t=a[i];
a[i]=a[high];
a[high]=t;
high--;
}
elseif(a[i]==0)
i++;
else
{
t=a[i];
a[i]=a[low];
a[low]=t;
low++;
i++;
}
}
}
ints[]={8,4,0,-1,6,0,-5};
main()
{
inti;
printf("\nThearrybeforerestis:
\n");
for(i=0;iprintf("%4d",s[i]);
rest(s,sizeof(s)/sizeof(s[0]));
printf("\nThearryafterrestis:
\n");
for(i=0;iprintf("%4d",s[i]);
}
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#include
typedefstruct{charname[9];charsex;floatscore[2];}STU;
voidf(STUa)
{STUb={“Zhao”,’m’,85.0,90.0};inti;
strcpy(a.name,b.name);
a.sex=b.sex;
for(i=0;i<2;i++)a.score[i]=b.score[i];
}
main()
{STUc={“Qian”,’p’,95.0,92.0};
f(c);
printf(“%s,%c,%2.0f,%2.0f\n”,c.name,c.sex,c.score[0],c.score[1]);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
main()
{
intx,y,z,j=0;
printf("\nThepossibleplanstobuy100fowlswith100Yuanare:
\n\n");
for(x=0;x<=20;x++)
for(y=0;y<=33;y++){
z=100-x-y;
if(z%3==0&&5*x+3*y+z/3==100)
printf("%2d:
cock=%2dhen=%2dchicken=%2d\n",++j,x,y,z);
}
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
voidfun(intx)
{if(x/2>0)fun(x/2);
printf(“%d”,x);
}
main()
{fun(3);
printf(“\n”);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#defineMAX(a,b)(a>b)?
a:
b
main()
{
intx,y;
x=25;
y=56;
printf("theresultis:
%d\n",MAX(x,y));
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#defineROWS4
#defineCOLS4
intnums[ROWS][COLS]={{1000,1000,1000,1000},
{900,500,400,100},
{90,50,40,10},
{9,5,4,1}};
char*roms[ROWS][COLS]={{"m","m","m","m"},
{"cm","d","cd","c"},
{"xc","l","xl","x"},
{"ix","v","iv","i"}};
main(intargc,char*argv[])
{
intlow=1000,high=1012;
charroman[25];
for(;low<=high;low++)
{
to_roman(low,roman);
printf("%d\t%s\n",low,roman);
}
system("pause");
}
to_roman(intdecimal,charroman[])
{
intpower,index;
roman[0]='\0';
for(power=0;powerfor(index=0;indexwhile(decimal>=nums[power][index])
{
strcat(roman,roms[power][index]);
decimal-=nums[power][index];
}
}
程序的运行结果是
#include
intFun(intx)
{
staticinty=0;
y+=x;
returny;
}
main()
{
intx=10,y=0,k;
for(k=0;k<2;k++)
{
y=Fun(x);
printf("y=%d\n",y);
}
}
运行结果是:
#include
main()
{
chara[]="programming",b[]="language";
char*p1,*p2;
inti;
p1=a;
p2=b;
for(i=0;i<7;i++)
{
if(*(p1+i)==*(p2+i))
printf("%c",*(p1+i));
}
printf("\n");
}
运行结果是:
#include
main()
{
inta=10;
{
inta=15;
printf(“a.1=%d,”,a);
}
printf(“a.2=%d\n”,a);
}
运行结果是:
#include
main()
{
inti=0;
while
(1)
{
printf(“*”);
i++;
if(i<3)break;
}
printf(“\n”);
}
运行结果是:
intrunc(inta,intb)
{return(a+b);}
main()
{
intx=2,y=5,z=8,r;
r=runc(runc(x,y),z);
printf(“%d\n”,r);
}
执行结果是:
阅读以下程序并写出其运行结果
#incude
main()
{
inti,n3,n2,n1;
i=1;
while(i<=99){
n3=i/100;
n2=(i-n3*100)/10;
n1=i%10;
if((i%3==0)&&(n2==5||n1==5))
printf("%5d",i);
i++;
}
}
程序的运行结果是
阅读以下程序并写出其运行结果
main()
{inta[6][6],i,j;
for(i=1;i<6;i++)
for(j=1;j<6;j++)
a[i][j]=(i/j)*(j/i);
for(i=1;i<6;i++){
for(j=1;j<6;j++)
printf(“%2d”,a[i][j]);
printf(“\n”);
}
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#include
structks{
inta;int*b;
}s[4],*p;
main()
{intn=1,i;
for(i=0;i<4;i++){
s[i].a=n;s[i].b=&s[i].a;n=n+2;
}
p=&s[0];p++;
printf(“%d,%d\n”,(++p)->a,(p++)->a);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
voidfun(int*s,intnl,intn2)
{inti,j,t;
i=nl;j=n2;
while(i}
main()
{inta[10]={1,2,3,4,5,6,7,8,9,0},k;
fun(a,0,3);fun(a,4,9);fun(a,0,9);
for(k=0;k<10;k++)printf(“%d”,a[k]);printf(“\n”);
}
程序运行的结果是
阅读以下程序并写出其结果
func(inta,intb)
{staticintm=0,i=2;
i+=m+1;
m=i+a+b;
return(m);
}
main()
{intk=4,m=1,p1,p2;
p1=func(k,m);p2=func(k,m);
printf(“%d,%d\n”,p1,p2);
}
程序的运行结果是
阅读以下程序并写出其运行结果
structman{
charname[20];intage;
}person[]={“liming”,18,“wanghua”,19,”zhangping”,20};
main()
{intold=0;
structman*p=person,*q;
for(;p<=&person[2];p++)
if(oldage){q=p;old=p->age};
printf(“$s%d\n”,q->name,q->age);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
main()
{
intx,y,z,j=0;
printf("\nThepossibleplanstobuy100fowlswith100Yuanare:
\n\n");
for(x=0;x<=20;x++)
for(y=0;y<=33;y++){
z=100-x-y;
if(z%3==0&&5*x+3*y+z/3==100)
printf("%2d:
cock=%2dhen=%2dchicken=%2d\n",++j,x,y,z);
}
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
voidfun(intx)
{if(x/2>0)fun(x/2);
printf(“%d”,x);
}
main()
{fun(3);
printf(“\n”);
}
程序的运行结果是
阅读以下程序并写出其运行结果
#defineMAX(a,b)(a>b)?
a:
b
main()
{
intx,y;
x=25;
y=56;
printf("theresultis:
%d\n",MAX(x,y));
}
程序的运行结果是
阅读以下程序并写出其运行结果
#include
#defineROWS4
#defineCOLS4
intnums[ROWS][COLS]={{1000,1000,1000,1000},
{900,500,400,100},
{90,50,40,10},
|
|