浙江大学C语言总复习题--综合(4)

2018-12-15 17:34

}

15.#include int c;

func(int *a,int b)

{ c=(*a)*b; *a=b-1; b++; return(*a+b+1); }

main()

{ int a=4, b=2, p=0; p=func(&b, a);

printf(\ }

16.#include void p(int x,int *y)

{ *y=x++; }

void main()

{ int x=0, y=0; p(10,&y);

printf(\ p(y,&x);

printf(\ }

17.#include

func(int a,int b,int *c,int *d)

{ *c=a+b; *d=a-b; a++; b++; }

main()

{ int a=4, b=3, c=2,d=1; func(d,c,&b,&a);

printf(\ }

18.#include

func(int *a,int n,int *b)

{ int k;

for(k=0;k

main()

{ int a[6]={1,2,3}, b=0,k; func(a, 3,&b);

for(k=0;k<3;k++) printf(―%d#‖,a[k]); printf(\ }

19.#include void main() {

long in, power, i;

15

int num;

scanf(\

for(power=1;in/power>0;power*=10); power/=10;

while(power>0){

printf(\ in%=power; power/=10; } }

输入02345<回车> 20. #include void main() {

int m=0,sum=0; char c,oldc='+';

do {

c=getchar();

if(c<='9'&&c>='0') m=10*m+c - '0'; else {

if(oldc=='+') sum += m; else sum -= m; m=0; oldc=c; }

} while(c!='='); printf(\ }

输入 -12+3*10=<回车> 21. #include void main()

{

int n; char ch; do{

ch=getchar();

}while(ch<'0'||ch>'7'); n=0; do{

n=n*8+(ch-'0'); ch=getchar();

}while(ch>='0'&&ch<='7'); printf(\

}

输入 afds2008b3c<回车> 22. #include

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

16

void main() { int s,k;

for(s=0,k=0; k<3; k++) s+=a[k][k]; printf(\

for(s=0,k=0; k<3; k++) s+=a[k][3-k]; printf(\

for(s=0,k=0; k<4; k++) s+=*(a[1]+k); printf(\

}

23. #include

int cal( int a, int b, char op) { if (op==?*‘) return (a*b); else return (a+b); }

main()

{ int x,y,z, result; char op1, op2;

scanf(―%d%c%d%c%d‖, &x, &op1, &y, &op2, &z); if (op2==?+‘ && op1 ==?*‘)

result = cal(x, cal(y,z,op2), op1); else result = cal(cal(x,y,op1),z,op2); printf(―%d#‖, result); }

输入 2+3*5<回车> 24.#include void main()

{ static char a[5]={'a','e','i','o','u'}; char str[80]; int k,j; gets(str);

for(k=0;str[k]!='\\0';k++) for(j=0;j<5;j++)

if (str[k]==a[j]) str[k]=j+'0'; puts(str); }

输入I am a student.<回车>

25.若head是node类型的全程量,以head为头指针的链表各节点的值如下图所示。 #include struct node { int num;

struct node *next; };

struct node *head ; int fun(struct node *h)

17

{ int k=0;

struct node *p=h; while(p!=NULL){ 2 head k+=p->num; 1 3 4 7 NULL p=p->next; }

return k; }

main() { int m;

m=fun(head);

printf(―m=%d\\n‖,m); }

26.若head是node类型的全程量,以head为头指针的链表各节点的值如下图所示。 #include struct node { int num;

struct node *next; };

struct node *head; int fun(struct node *h)

{ int k=0;

struct node *p=h; while(p!=NULL){

if(p->next!=NULL) k+=p->num; p=p->next; } 14 13 15 16 17 NULL head return k; } main()

{ int m; m=fun(head);

printf(―m=%d\\n‖,m); }

27.若head是node类型的全程量,以head为头指针的链表各节点的值如下图所示。 #include

struct node { int num;

struct node *next; };

struct node *head; int fun(struct node *p) { int k=0;

struct node *pp=p; while (pp!=NULL) {

18

if ((pp->num)%2==0) k+=pp->num; pp= pp->next; }

return (k); } head 4 3 5 6 7 NULL main() { int m;

m=fun(head);

printf(―m=%d\\n‖,m); }

28.若head是node类型的全程量,以head为头指针的链表各节点的值如下图所示。 #include struct node { int num;

struct node *next; };

struct node *head; int fun(struct node *h) { int k=0;

struct node *p=h;

p = head->next ; p = p->next ; while (p!=NULL) {

k+=p->num; p= p->next; } head return (k); 10 20 30 40 50 NULL

} main()

{ int m;

m=fun(head);

printf(―m=%d\\n‖,m); }

29.若head是node类型的全程量,以head为头指针的链表各节点的值如下图所示。 #include struct node { char c;

struct node *next; };

struct node *head;

void fun(struct node *h) { struct node *p=h; while(p!=NULL) {

if(p->c>='A' && p->c<='Z') putchar((*p).c); p=p->next;}

19


浙江大学C语言总复习题--综合(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:微机原理与接口技术试题库(含答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

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