南昌大学 信工学院 C 语言程序设计 综合练习

时间:2025-04-20

南昌大学 信工学院 C 语言程序设计 综合练习

一、 简答题

1. 用N-S图表示判断素数的算法。

2. 阅读以下程序,写出程序的运行结果:

#include <stdio.h>

void main()

{

char c1,c2;

c1='a';

c2='b';

c1=c1-32;

c2=c2-32;

printf("%c %c",c1,c2);

}

程序运行结果为__A B__________________

3. 阅读以下程序,写出程序的运行结果:

main()

{

int c=5;

printf("%d,%d,%d\n",c+=c++,c+8,++c);

c=5;

printf("%d\n",(c+=c++,c+8,++c));

c=5;

printf("%d\n",c+=c++,c+8,++c);

}

程序运行结果为_:12,14,6

12

12_

4阅读以下程序,写出程序的运行结果:

main ( )

{

int day,x1,x2;

day=9;

x2=1;

while(day>0){

x1=(x2+1)*2;

x2=x1;

day--;

}

printf(“total=%d\n”,x1);

}

程序运行结果为____________________

4. 阅读以下程序,写出程序的运行结果:

#include <stdio.h>

void main()

{

int i;

int f[10]={1,1};

for(i=2;i<10;i++)

f[i]=f[i-2]+f[i-1];

for(i=0;i<10;i++)

{

if(i%5==0) printf("\n");

printf("%12d",f[i]);

南昌大学 信工学院 C 语言程序设计 综合练习

}

} 程序运行结果为____________________

5. 阅读以下程序并写出其运行结果

#include <stdio.h>

main()

{ int x=1,y=0,a=0,b=0;

switch(x)

{ case 1:

switch(y)

{ case 0: a++; break;

case 1: b++; break;

}

case 2: a++; b++; break;

case 3: a++; b++;

}

printf(“a=%d,b=%d\n”,a,b);

}

程序的运行结果是

6. 阅读以下程序并写出其运行结果

#include <stdio.h>

main()

{ int a[ ]={1,2,3,4},y,*p=&a[3];

--p; y=*p; printf(“y=%d\n”,y);

}

程序的运行结果是

7. 阅读以下程序并写出其运行结果

#include <stdio.h>

void fun(int *s, int nl, int n2)

{ int i, j, t ;

i=nl; j=n2;

while(i<j) { t=s[i]; s[i]=s[j]; s[j]=t; i++; j--; }

}

main()

{ int a[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”);

}

程序运行的结果是

8. 阅读以下程序并写出其运行结果

#include <stdio.h>

int f(int x)

{ int y;

if(x==0||x==1) return (3);

y=x*x-f(x-2);

return y;

}

main()

{ int z;

z=f(3);

printf(“%d\n”,z);

}

程序的运行结果是

9. 阅读以下程序并写出其运行结果

#include <stdio.h>

#include <string.h>

typedef struct { char name[9]; char sex; float score[2];

void f( STU a)

} STU;

南昌大学 信工学院 C 语言程序设计 综合练习

{ STU b={“Zhao” , m ,85.0,90.0} ; int i;

strcpy(http://,http://);

a.sex=b.sex;

for(i=0;i<2;i++) a.score[i]=b.score[i];

}

main()

{ STU c={“Qian”, p ,95.0,92.0};

f(c);

printf(“%s,%c,%2.0f,%2.0f\n”,http://,c.sex,c.score[0],c.score[1]);

}

程序的运行结果是

10.阅读以下程序,写出程序的运行结果:

#include <stdio.h>

void main()

{

int i,j,row=0,colum=0,max;

int a[3][4]={{1,2,3,4},{9,8,7,6},{-10,10,-5,2}};

max=a[0][0];

for (i=0;i<=2;i++)

for (j=0;j<=3;j++)

if (a[i][j]>max)

{max=a[i][j];

row=i;

colum=j;

}

printf("max=%d,row=%d,colum=%d\n",max,row,colum);

}

程序运行结果为____________________

11.阅读以下程序,写出程序的运行结果:

#include <stdio.h>

#define PI 3.1415926

#define S(r) PI*r*r

void main()

{float a,area;

a=3.6;

area=S(a);

printf("r=%6.2f\narea=%6.2f\n",a,area);

}

程序运行结果为____________________

12.阅读以下程序,写出程序的运行结果:

#include <stdio.h>

void main()

{

void exchange(int *q1, int *q2, int *q3);

int a,b,c,*p1,*p2,*p3;

a = 22; b = 56; c = 128;

p1=&a;p2=&b;p3=&c;

exchange(p1,p2,p3);

printf("\n%d,%d,%d\n",a,b,c);

}

void exchange(int *q1, int *q2, int *q3)

{

void swap(int *pt1, int *pt2);

if(*q1<*q2) swap(q1,q2);

南昌大学 信工学院 C 语言程序设计 综合练习

if(*q1<*q3) swap(q1,q3);

if(*q2<*q3) swap(q2,q3);

}

void swap(int *pt1, int *pt2)

{

int temp;

temp=*pt1;

*pt1=*pt2;

*pt2=temp;

}

程序运行结果为____________________

13.阅读以下程序,写出程序的运行结果:

#include <stdio.h>

void main()

{

int fac(int n);

int i;

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

printf("%d!=%d\n",i,fac(i));

}

int fac(int n)

{

static int f=1;

f=f*n;

return(f);

}

程序运行结果为____________________

14.阅读以下程序,写出程序的运行结果:

#include <stdio.h>

void main()

{

int n;

for (n=100;n<=120;n++)

{if (n%3==0)

continue;

printf("%d ",n);

}

}

程序运行结果为____________________

15.阅读以下程序并写出其运行结果

#include<stdio.h>

main()

{ int x[]={1,2,3,4,5 …… 此处隐藏:8559字,全部文档内容请下载后查看。喜欢就下载吧 ……

南昌大学 信工学院 C 语言程序设计 综合练习.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:7 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:29元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219