现在的位置: 首页 > 14 二级C语言 > 正文

2011年秋 阅读程序 题目解析

2012年09月16日 14 二级C语言 ⁄ 共 588字 ⁄ 字号 暂无评论

把程序运行一下,就知道结果了。

6. 以下程序运行时输出到屏幕的结果为 (6)

1
2
3
4
5
6
7
8
#include<stdio.h>
enum color {BLACK,YELLOW,BLUE=3,GREEN,WHITE};
void main()
{
    char *colorname[]= {"Black","Yellow","Blue","Green","White"};
    enum color c1=GREEN,c2=BLUE;
    printf("%s",colorname[c1-c2]);
}

7. 以下程序运行时输出到屏幕的结果是 (7)

1
2
3
4
5
6
7
8
9
10
11
#include<stdio.h>
void main()
{
    int a=0,b=1,d=10;
    if(a)
        if(b)
            d=20;
        else
            d=30;
    printf("%d\n",d);
}

8. 以下程序运行时,输出到屏幕的结果中第一行是___(8)___,第二行是___(9)___。

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<stdio.h>
void fun(int a,int *b)
{
    a++;
    (*b)++;
}
 
void main()
{
    int a[2]= {1,1};
    fun(a[0],&a[1]);
    printf("%d\n%d",a[0],a[1]);
}

9.以下程序运行时,输出到屏幕的结果中第一行是___(10)___,第二行是___(11)___,第三行是___(12)___。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
#include<math.h>
 
void main()
{
    int a[100]= {0},i,j,k;
    for(i=1; i<100; i++)
        a[i]=i+1;
    printf("%4d%4d%4d\n",a[0],a[1],a[2]);
    for(j=1; j<100; j++)
    {
        if(a[j]!=0)
            for(k=j+1; k<100; k++)
                if(a[k]%a[j]==0)
                    a[k]=0;
    }
    for(k=1,i=0; k<100; k++)
        if(a[k]!=0)
        {
            printf("%4d",a[k]);
            i++;
            if(i%3==0)printf("\n");
        }
}

10.以下程序运行时,输出到屏幕的结果中第一行是___(13)___,第二行是___(14)___。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<stdio.h>
#include<math.h>
 
int fun(int a,int b)
{
    int n;
    while(a!=b) {
        n=abs(a-b);
        a=(a>b)?b:a;
        b=n;
    }
    return a;
}
void main()
{
    printf("%d\n%d\n",fun(9,15),fun(9,5));
}

11.以下程序运行时,输出到屏幕的结果中第一行是___(15)___,第二行是 ___(16)___。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
int fun1(int p[ ],int n)
{
    int i,s=0;
    for(i=0; i<n; i++)
        s+=p[i];
    return s;
}
 
int fun2(int *s,int n)
{
    if(n==1)
        return *s;
    else
        return (*s)+fun2(s+1,n-1);
}
 
void main()
{
    int a[]= {1,2,3,4,5};
    printf("%d\n%d",fun1(a,3),fun2(a,3));
}

12.以下程序运行时,输出到屏幕的结果中第一行是__(17)___,第二行是___(18)___ 。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<string.h>
 
int fun(char str[])
{
    int i,j,len;
    len=strlen(str);
    for(i=0,j=0; str[i]; i++)
        if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
            str[j++]=str[i];
    str[j]='\0';
    return len-j;
}
 
void main()
{
    char ss[80]="It23is!";
    int n;
    n=fun(ss);
    printf("%d\n%s\n",n,ss);
}

抱歉!评论已关闭.