2016 年全國高等學校(安徽考區)
(二級 C 語言程序設計)
一、程序填空題(每題 12 分,共 36 分。將答案填寫在相應的下劃線處)
1. 以下程序將依次輸出"12345654321",請填空。
#include<stdio.h> void main()/<stdio.h>
{
int a=12345,b=54321, ;
char ch='A'; c=a/ ;
printf("%4d%d",c,5);//12345 printf("%d",ch);
c=b% ;
printf("%4d",c);//4321
}
2. 以下程序輸入 3 個整型數並輸出其中的中間數,如輸入 5、3、4,將輸出 4。請填空。#include<stdio.h>
void main()
{
int a,b,c; int max,min;
printf("input a,b,c:");
scanf("%d%d%d", );//順序輸入 a,b,c 的值
if(a>b)
{
max=a; min=b;
}
else
{
max=b; min=a;
}
if(c>max)
printf("%d",max); else if(c
{
printf("%d", );
}
else printf("%d", );
1
3. 以下程序輸出一個字符串中所有的字母,其他字符不輸出。如果是小寫字母,輸出時轉換成大寫字母。請填空。
#include<stdio.h> void main()/<stdio.h>
{
int i;
char s[]="C Programing."; char c,*p=&c;
i= ; while(s[i]!='\0')
{
*p=s[i]; if(c>='A'&&c<='Z')
printf("%c", ); else
if(c>='a'&&c<='z')
printf("%c", );
i++;
}
}
二、閱讀程序題(每題 8 分,共 32 分。將答案填寫在相應的下劃線處)
1. 以下程序的運行結果是 。
#include<stdio.h> void main()/<stdio.h>
{
int a=3,b=5,c=4,t; if(a
{
t=a; a=b; b=t;
}
if(b
{
t=b; b=c; c=t;
}
if(a
{
t=a; a=b; b=t;
}
printf("a=%d,b=%d,c=%d",a,b,c,t);
}
2. 以下程序的運行結果是 。
#include<stdio.h> void main()/<stdio.h>
{
int i;
int a[5]= {1,2,3,4,5},t=0;
for(i=0; i<5; i++)
{
switch(a[i]%3)
{
case 0:
t=t+a[i]; break;
case 1:
t=t-a[i]; break;
default:
t=t+1;
}
}
printf("i=%d,t=%d",i,t);
}
3. 以下程序的運行結果是 。
#include<stdio.h> int max(int a,int b)/<stdio.h>
{
if(a>b)
return a; else
return b;
}
void main()
{
int i,m;
int a[5]={212,134,423,545,356};
for(i=0;i<2;i++) m=max(a[i],a[i+1]);
printf("i=%d,m=%d",i,m);
}
4. 以下程序的運行結果是 。
#include<stdio.h>
int f(int n)//遞歸函數 f
{
if(n==1)
return 1; else
return n+f(n-1);
}
void main()
{
int i; for(i=1;i<=4;i++)
printf("%d",f(i));
}
三、程序設計題(每題 16 分,共 32 分)
1. 編程輸出 100 以內所有含數字 4 的偶數的和。
2. 由於霧霾紅色預警,車輛將限號出行,規定如下:
(1)尾號是 0,2,4,6,8,雙日出行,例如:AZ7Y68,WJ-2126
(2)尾號是其他數字、字母或符號的,單日出行,例如:AZ7Y69,WJ-2127,B3300B
請完善下面的程序以實現上面描述的功能。要求根據輸入的車牌號分別輸出"雙日出行"或
"單日出行"。#include<stdio.h> void main()/<stdio.h>
{
char s[10];//用於存儲車牌號int i;
printf("Input s:"); scanf("%d",&s); //輸入車牌號
//請在下面編寫和完善程序
4