南昌大学C语言题目 综合练习Word文档格式.docx
《南昌大学C语言题目 综合练习Word文档格式.docx》由会员分享,可在线阅读,更多相关《南昌大学C语言题目 综合练习Word文档格式.docx(46页珍藏版)》请在冰豆网上搜索。
![南昌大学C语言题目 综合练习Word文档格式.docx](https://file1.bdocx.com/fileroot1/2023-1/31/d2bf85f1-f7a4-4a86-855f-9b4c49899c6e/d2bf85f1-f7a4-4a86-855f-9b4c49899c6e1.gif)
i=nl;
j=n2;
while(i<
j){t=s[i];
s[i]=s[j];
s[j]=t;
i++;
j--;
}
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;
\n>
>
Theladderhas%dstages.\n"
i);
#defineROW3
#defineCOL4
intmatrixA[ROW][COL]={11,12,13,14,15,16,17,18,19,20,21,22};
intmatrixB[COL][ROW];
inti,j;
%d*%d:
\n"
ROW,COL);
for(i=0;
i<
ROW;
i++){
for(j=0;
j<
COL;
j++){
matrixB[j][i]=matrixA[i][j];
}
MatrixB,"
COL,ROW);
for(j=0;
printf("
%8d"
matrixB[i][j]);
printf("
#defineN10
intprimes[N];
intpc,m,k;
\nThefirst%dprimenumbersare:
N);
primes[0]=2;
pc=1;
m=3;
while(pc<
N)
{
k=0;
while(primes[k]*primes[k]<
=m)
if(m%primes[k]==0)
{
m+=2;
k=1;
else
k++;
primes[pc++]=m;
m+=2;
pc;
k++)
%4d"
primes[k]);
程序的运行结果是
string.h>
voidfun(char*s[],intn)
{char*t;
inti,j;
for(i=0;
i<
n-1;
i++)
for(j=i+1;
j<
n;
j++)
if(strlen(s[i])>
strlen(s[j])){t=s[i];
s[i]=s[j];
s[j]=t;
{char*ss[]={“bcc”,”bbcc”,”xy”,”aaaacc”,”aabcc”};
fun(ss,5);
printf(“%s,%s\n”,ss[0],ss[4]);
voidfun(char*a,char*b)
{while(*a==’*’)a++;
while(*b=*a){b++;
a++;
{char*s=”****a*b****”,t[80];
fun(s,t);
puts(t);
{FILE*fp;
inta[10]={1,2,3},i,n;
fp=fopen(“dl.dat”,”w”);
for(i=0;
3;
i++)fprintf(fp,”%d”,a[i]);
fprintf(fp,”\n”);
fclose(fp);
fp=fopen(“dl.dat”,”r”);
fscanf(fp,”%d”,&
n);
printf(“%d\n”,n);
voidswap(int*a,int*b)
{int*t;
t=a;
a=b;
b=t;
{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};
sizeof(num)/sizeof(num[0]);
for(j=0;
sizeof(scale)/sizeof(scale[0]);
if(circle(num[i],scale[j]))
printf("
%d->
(%d)isaCircleNumber!
num[i],scale[j]);
else
(%d)isnotaCircleNumber!
#defineNULL0
int*search2(int*pa,int*pb,intan,intbn)
int*ca,*cb;
ca=pa;
cb=pb;
while(ca<
pa+an&
cb<
pb+bn)
if(*ca<
*cb)
ca++;
elseif(*ca>
cb++;
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:
"
sizeof(a)/sizeof(a[0]);
%d"
a[i]);
\nTheelementsofarraybis:
sizeof(b)/sizeof(b[0]);
b[i]);
vp=search2(a,b,sizeofa/sizeofa[0],sizeofb/sizeofb[0]);
if(vp)printf("
\nThefirstsamenumberinbotharraysis%d\n"
*vp);
elseprintf("
Notfound!
inti,j;
i=1;
=5){
j=1;
ch='
a'
while(j<
=i){
%2c"
ch);
ch=ch+1;
j++;
i++;
rest(inta[],intn)
inti,low,high,t;
for(i=0,low=0,high=n-1;
=high;
)
if(a[i]>
0)
t=a[i];
a[i]=a[high];
a[high]=t;
high--;
elseif(a[i]==0)
i++;
a[i]=a[low];
a[low]=t;
low++;
ints[]={8,4,0,-1,6,0,-5};
inti;
\nThearrybeforerestis:
sizeof(s)/sizeof(s[0]);
s[i]);
rest(s,sizeof(s)/sizeof(s[0]));
\nThearryafterrestis:
typedefstruct{charname[9];
charsex;
floatscore[2];
}STU;
voidf(STUa)
{STUb={“Zhao”,’m’,85.0,90.0};
strcpy(a.name,b.name);
a.sex=b.sex;
2;
i++)a.score[i]=b.score[i];
{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;
\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)
%2d:
cock=%2dhen=%2dchicken=%2d\n"
++j,x,y,z);
voidfun(intx)
{if(x/2>
0)fun(x/2);
printf(“%d”,x);
{fun(3);
#defineMAX(a,b)(a>
b)?
a:
b
intx,y;
x=25;
y=56;
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"
"
},
{"
cm"
d"
cd"
c"
xc"
l"
xl"
x"
ix"
v"
iv"
i"
}};
main(intargc,char*argv[])
intlow=1000,high=1012;
charroman[25];
for(;
low<
low++)
to_roman(low,roman);
%d\t%s\n"
low,roman);
to_roman(intdecimal,charroman[])
intpower,index;
roman[0]='
\0'
for(power=0;
power<
ROWS;
power++)
for(index=0;
index<
COLS;
index++)
while(decimal>
=nums[power][index])
{
strcat(roman,roms[power][index]);
decimal-=nums[power][index];
}
intFun(intx)
staticinty=0;
y+=x;
returny;
intx=10,y=0,k;
for(k=0;
k<
k++)
y=Fun(x);
y=%d\n"
y);
运行结果是:
main()
chara[]="
programming"
b[]="
language"
;
char*p1,*p2;
inti;
p1=a;
p2=b;
for(i=0;
7;
i++)
if(*(p1+i)==*(p2+i))
%c"
*(p1+i));
inta=10;
inta=15;
printf(“a.1=%d,”,a);
printf(“a.2=%d\n”,a);
inti=0;
while
(1)
printf(“*”);
if(i<
3)break;
printf(“\n”);
intrunc(inta,intb)
{return(a+b);
intx=2,y=5,z=8,r;
r=runc(runc(x,y),z);
printf(“%d\n”,r);
执行结果是:
#incude<
inti,n3,n2,n1;
=99){
n3=i/100;
n2=(i-n3*100)/10;
n1=i%10;
if((i%3==0)&
(n2==5||n1==5))
%5d"
i);
main()
{inta[6][6],i,j;
for(i=1;
6;
for(j=1;
j++)
a[i][j]=(i/j)*(j/i);
i++){
printf(“%2d”,a[i][j]);
structks{
inta;
int*b;
}s[4],*p;
{intn=1,i;
for(i=0;
4;
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);
阅读以下程序并写出其结果
func(inta,intb)
{staticintm=0,i=2;
i+=m+1;
m=i+a+b;
return(m);
{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};
{intold=0;
structman*p=person,*q;
for(;
p<
=&
person[2];
p++)
if(old<
p->
age){q=p;
old=p->
age};
printf(“$s%d\n”,q->
name,q->
age);