考研C语言程序理解题

程序理解题(指出程序执行的结果)

1. #include <stdio.h>

main( )

{ int i,j,x=0;

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

{ x++;

for (j=0;j<3;j++) { if (j%2 ) continue;

x++;

}

x++;

}

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

}

  1. #include <stdio.h>

main( )

{ int k=0,j,x=0;

while (k<2)

{ ++x;

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

{ if (j%2 ) break;

x++;

}

k++; ++x;

}

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

}

3.#include <stdio.h>

main()

{int a=2,b=7,c=5;

switch (a>0)

{case 1:switch (b<0)

{ case 1: printf("$");break;

case 2: printf("!"); break;

}

case 0: switch (c= =5)

{ case 0: printf("*");break;

case 1:printf("#");break;

default: printf("%");

}

default: printf("&");

} printf("\n");

}

  1. main()

{ int i,sum=0;

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

{ sum+=i;

if (sum>10) break;

printf("sum=%-5d\n",sum);

}

}

  1. 若输入字符串program时,下列程序输出为:

#include <stdio.h>

main()

{ char str80;

void prochar(char *str,char ch);

scanf("%s",str);

prochar(str,'r');

puts(str);

}

void prochar(char *str,char ch)

{ char *p;

for (p=str;*p!='\0';p++)

if (*p==ch){*str=*p;(*str)++;str++;}

*str='\0';

}

  1. #include <stdio.h>

#include <string.h>

main()

{ int i,j,temp, d44={{1,2,3,4},{5,6,7,8},{4,3,2,1},{1,2,3,4}};

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

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

if (dij>dji) dji=dij;

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

{ printf("\n");

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

if (j>=i) printf("%6d",dij ) ;

else printf("%6c",' ') ;

}

}

  1. #include<stdio.h>

main()

{ int k;

printf("\n");

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

switch(k%2)

{case 0: printf("#");break;

case 1: k+=2;printf("*");

defalt: printf("\n");

}

}

8. int d=1;

fun(int p)

{ static int d=5;

d+=p;

printf("(f)%-4d",d);

return (d);

}

main()

{int a=3;

printf("\n(m)%d",fun(a*fun(d)));

}

  1. #include <stdio.h>

main()

{char a26={"sun","moon"};

int j,i,len2;

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

{ for (j=0;j<6;j++)

if (aij=='\0')

{ leni=j;

break;

}

printf("%8s:%d\n",ai,leni);

}

  1. int x=2,y=4;

f1(int x)

{ x++;y++;

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

}

f2(int *y)

{ x++;(*y)++;

printf("f2:x=%d,y=%d\n",x,*y);

}

main()

{ int y=6;

f1(x);f2(&y);

printf("main:x=%d,y=%d",x,y);

}

程序理解题(指出程序执行的结果)

1. x=8

  1. 程序输出为:x=6

  2. 程序输出为:#&

  3. 程序输出为: sum=1 sum=3 sum=6 sum=10

5.当键盘输入program.时,下列程序的输出: pogam

  1. 程序输出为: 1 5 4 4 6 7 8 2 3 4

  2. 程序输出为: * #* #*

  3. 程序输出为: (f)6 (f)24 (m)24

9 . sun:3 moon:4

  1. f1:x=3 ,y=5 f2:x=3 ,y=7 main:x=3 ,y=7
相关推荐
Lee_jerome14 小时前
《C/C++编译全家桶:g++四阶段、.a与.so区别、CMake构建、ARM交叉编译,这篇全讲透了》
c语言·开发语言·arm开发·c++·编译·cmake·cmakelists
浩浩kids15 小时前
C•exercises
c语言
春生野草16 小时前
个人笔记——C语言字符串、树
c语言·开发语言·笔记
ysu_031417 小时前
用Vibe-Coding从零实现俄罗斯方块
c语言·游戏程序
冻柠檬飞冰走茶21 小时前
PTA基础编程题目集 7-24 约分最简分式(C语言实现)
c语言·开发语言·数据结构·算法
weixin_585951171 天前
CH592F 2.4G 低功耗
c语言·开发语言
盒子里的加菲猫1 天前
什么?不会C语言也可以搭建窗口级应用程序?(Electron)
c语言·开发语言·electron
caishenzhibiao1 天前
无极多空共振 同花顺期货通指标
java·c语言·c#
modelmd1 天前
C 语言基础数据类型详解:大小与内存存储
c语言
hjlgs1 天前
七. C语言形参-实参
c语言·开发语言