當前位置:首頁 » 編程語言 » 內江c語言青少年編程考題
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

內江c語言青少年編程考題

發布時間: 2022-12-10 12:33:08

A. 求C語言的筆試題和編程題!!~~~謝謝~~!!

一份曾經的考卷+答案~~//後面的編程題是以前做過的實驗~~

《程序設計基礎-C》試卷
一、單項選擇題
1. C 語言程序中可以對程序進行注釋,注釋部分必須用符號_____括起來。
A、『{『 和』}』 B、『[『和』]』 C、「/*」和」*/」 D、「*/」和」/*」
2. 下列運算符中,優先順序最低的是_____。
A、* B、!= C、+ D、=
3. 若變數已正確定義,表達式 (j=3, j++) 的值是_____ 。
A、3 B、 4 C、5 D、0
4. 已知字元 『a』 的ASCII碼為 97 ,執行下列語句的輸出是_____。
printf ("%d, %c", 』b』, 』b』+1 ) ;
A、98, b B、語句不合法 C、98, 99 D、 98, c
5. 表達式strcmp(「box」, 「boss」) 的值是一個_______。
A、 正數 B、 負數 C、 0 D、 不確定的數
6. 數組定義為 int a[3][2]={1, 2, 3, 4, 5, 6},數組元素_____的值為6。
A、a[3][2] B、a[2][1] C、a[1][2] D、a[2][3]
7. 要調用數學函數時,在#include命令行中應包含_____。
A、 」stdio.h」 B、 」string.h」 C、 」math.h」 D、 」ctype.h」
8. 判斷i和j至少有一個值為非0的表達式是_____。
A、 i!=0 && j!=0 B、i*j!=0 C、!(i==0 || j==0) D、i&&j
9. 若a是基本整型變數,c是單精度實型變數,輸入語句______是錯誤的。
A、scanf(」%d,%f」, &a, &c); B、scanf(」d=%d, c=%f」, &a, &c);
C、scanf(」%d%f」, &a, &c); D、scanf(」%d%f」, a, c);
10. 若變數已正確定義並且指針p已經指向某個變數x,則(*p)++相當於_____。
A、p++ B、x++ C、*(p++) D、&x++
11. 若p1、p2都是整型指針,p1已經指向變數x,要使p2也指向x, _____是正確的。
A、p2=p1; B、p2=**p1; C、p2=&p1; D、p2=*p1;
12. 下列程序段的輸出是_____。
int c[]={1, 3, 5};
int *k=c+1;
printf("%d", *++k);
A、 3 B、 5 C、 4 D、6
13. 不正確的賦值或賦初值的方式是______。
A、char str[]="string";
B、char str[7]={'s', 't', 'r', 'i', 'n', 'g'};
C、char str[10];str="string";
D、char str[7]={'s', 't', 'r', 'i', 'n', 'g', 』\0』};
14. 對於以下結構定義,++p->str中的++加在_____。
struct {
int len;
char *str;
} *p;
A、指針str上 B、指針p上 C、str指的內容上 D、以上均不是
15. 對於如下說明,語法和語義都正確的賦值是_____。
int c, *s, a[]={1, 3, 5};
A、c=*s; B、 s[0]=a[0]; C、s=&a[1]; D、 c=a;

二、填空題
1. 寫出下列程序段的輸出結果。
float x1, x2;
x1=3/2;
x2=x1/2;
printf("%d, %.1f", (int)x1, x2) ;
2. 表達式 (7<<1>>2^2 ) 的值是_______。
3. 寫出下列程序段的輸出結果。
#define A 10
#define B (A<A+2)-2
printf("%d", B*2);
4. 寫出判斷字元變數c是英文字母的表達式 。
5. 寫出下列程序段的輸出結果。
int k, x;
for (k=0, x=0; k<=9&&x!=10; k++)
x+=2;
printf ("%d, %d", k, x) ;
6. 寫出下列程序段的輸出結果。
printf(「%d, %d」, NULL, EOF);
7. 對於以下遞歸函數f,調用 f (3) 的返回值是_____。
f (int n)
{ return ((n>0) ? 2*f(n-1)+f(n-2) : -1); }
8. 寫出下列程序段的輸出結果。
char str[]="hello\tworld\n";
printf("%d, %c\n", sizeof(str), *(str+10));
9. 輸入12345#後,寫出下列程序的輸出結果。
void main()
{ char c;
for(c=getchar(); getchar()!=』#』; c=getchar())
putchar(c);
}
10. 執行程序find –nx ould text.txt時,*++argv[1]的值是_______。
三、程序閱讀題
1. 若輸入 3 1 2 3 <回車> , 則以下程序的輸出結果是_______。
#include "stdio.h"
void main()
{ int i, j, n, a[10];
scanf("%d", &n);
for (i=0; i<n; i++)
scanf("%d",&a[i]);
for (i=0; i<n; i++)
for (j=0; j<n; j++)
printf("%d, ", a[(i+j)%n]);
}
2. 若輸入89 76 24 25 9 8 11 16 35 4 <回車> , 則以下程序的輸出結果是_______。
#include "stdio.h"
#define N 10
main()
{
int x[N], y1[N], y2[N];
int i, j, n1, n2, t, p;
n1=n2=0;
for(i=0;i<N;i++){
scanf(「%d」, &x[i]);
if(x[i] % 2==0) y1[n1++]=x[i];
else y2[n2++]=x[i];
}
for(i=1; i<n1; i++)
for(j=0; j<n1-1; j++)
if(y1[j]>y1[j+1]){
t=y1[j]; y1[j]=y1[j+1]; y1[j+1]=t;
}
for(i=0; i<n2-1; i++){
p=i;
for(j=i+1; j<n2; j++)
if(y2[p]<y2[j]) p=j;
if(p!=i){
t=y2[i]; y2[i]=y2[p]; y2[p]=t;
}
}
for(i=0; i<n1; i++) printf("%d, ", y1[i]);
for(i=0; i<n2; i++) printf("%d, ", y2[i]);
}
3. 以下程序的輸出結果是_______。
#include <stdio.h>
int z;
void p(int *x, int y)
{ ++*x;
y--;
z=*x+y+z;
printf("%d, %d, %d#", *x, y, z);
}
void main()
{ int x=1, y=5, z=9;
p(&x, y);
printf("%d, %d, %d#", x, y, z);
}
4. 若輸入 -6+15*3/5=<回車> , 則以下程序的輸出結果是_______。
#include <stdio.h>
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;
printf("%d, ", sum);
}
} while(c!='=');
}

四、程序填空題
下列程序的功能是創建單向鏈表。
#include <stdio.h>
#include <alloc.h>
struct link {
char name[10];
int mark;
struct link * next;
};
void insert(char *, int);
struct link * head = NULL;
main()
{
char name[10];
int mark;
struct link * t;
while ( 1 ) {
scanf("%s %d", name, &mark);
if ( strcmp(name, "#") == 0 ) break;
______(1)_______;
}
for (t=head; ______(2)_______)
printf("<%s>: %d\n", t->name, t->mark);
}
void insert(char * name, int mark)
{
struct link * p;
p = ______(3)_______ ;
strcpy(p->name, name);
p->mark = mark;
______(4)_______;
if ( head != NULL ) ______(5)_______;
head = p;
}

答案
2000~2001學年《程序設計基礎C》參考答案

一、單項選擇題
C D A D A B C B D B A B C A C
二、填空題
1 1, 0.5
2 1
3 -3
4 c>=』a』&&c<=』z』|| c>=』A』&&c<=』Z』
5 5, 10
6 0, -1
7 -17
8 13, d
9 13
10 『n』
三、程序閱讀題
1 1, 2, 3, 2, 3, 1, 3, 1, 2,
2 4, 8, 16, 24, 76, 89, 35, 25, 11, 9,
3 2, 4, 6#2, 5, 9#
4 0, -6, 9, 6, 1,
四、程序填空題
(1) insert(name, mark)
(2) t!=NULL; t=t->next
(3) (struct link *)malloc(sizeof(struct link))
(4) p->next = NULL
(5) p->next = head

編程
程序填空,不要改變與輸入輸出有關的語句。
輸入一個正整數repeat (0<repeat<10),做repeat次下列運算:
給定平面任意兩點坐標 (x1, y1) 和 (x2, y2),求這兩點之間的距離(保留2位小數)。
要求定義和調用函數 dist(x1, y1, x2, y2)計算兩點間的距離,函數形參x1、y1、x2和y2的類型都是double,函數類型是double。
輸入輸出示例:括弧內是說明
輸入
1 (repeat=1)
10 10 (x1=10, y1=10)
200 100 (x2=200, y2=100)
輸出
Distance = 210.24

#include <stdio.h>
#include <math.h>
double dist(double x1, double y1, double x2, double y2);
int main(void)
{
int repeat, ri;
double distance, x1, y1, x2, y2;

scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
/*---------*/
printf("Distance = %.2f\n", distance);
}
}

/*---------*/

程序填空。
求1~100中能被6整除的所有整數的和

#include <stdio.h>
int main(void)
{
int i, sum = 0;
/*---------*/
printf("%d", sum);
}

程序填空,不要改變與輸入輸出有關的語句。
輸入一個正整數repeat (0<repeat<10),做repeat次下列運算:
讀入1 個實數x和正整數 n(n<=50),計算並輸出 x 的 n 次冪(保留2位小數),不允許調用pow函數求冪。
輸入輸出示例:括弧內是說明
輸入
2 (repeat=2)
1.5 2 (x=1.5,n=2)
2 7 (x=2,n=7)
輸出
2.25
128.00

#include <stdio.h>
int main(void)
{
int i, n;
int repeat, ri;
double mypow, x;

scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%lf%d", &x, &n);
/*---------*/
printf("%.2f\n", mypow);
}
}

……編程題還有好多~~需要的話可以發給你~

B. C語言編程題

//樓上的,重量和金額怎麼能是整形的,還有輸入順序應切合實際,哈哈
/*
//if-else寫法
#include<stdio.h>
void main()
{
int grade; //等級
float weight; //重量
float money; //付款
float pay; //應付款
printf("請輸入購買信息:\n");
printf("蘋果等級:");
scanf("%d",&grade);
printf("蘋果重量:");
scanf("%f",&weight);
//數據驗證
if(weight<=0 || grade<1 || grade>4)
{
printf("Data Error!\n");
return;
}
//計算應付款
if(grade==1) //一級蘋果
pay=5.5*weight;
else if(grade==2) //二級蘋果
pay=4.2*weight;
else if(grade==3) //三級蘋果
pay=3*weight;
else //四級蘋果
pay=2.5*weight;

//顯示結果
printf("\n你所購買的是%d級蘋果:\n",grade);
printf("實際重量:%g\n",weight);
printf("應付金額:%g\n",pay);

printf("交付金額:");
scanf("%f",&money);
printf("\n應找零錢:%g\n",money-pay);
printf("謝謝惠顧,再見!\n");
}
*/
/*
//switch寫法
#include<stdio.h>
void main()
{
int grade; //等級
float weight; //重量
float money; //付款
float pay; //應付款
printf("請輸入購買信息:\n");
printf("蘋果等級:");
scanf("%d",&grade);
printf("蘋果重量:");
scanf("%f",&weight);
//數據驗證
if(weight<=0 || grade<1 || grade>4)
{
printf("Data Error!\n");
return;
}
//計算應付款
switch(grade)
{
case 1: //一級蘋果
pay=5.5*weight;break;
case 2: //二級蘋果
pay=4.2*weight;break;
case 3: //三級蘋果
pay=3*weight;break;
default: //四級蘋果
pay=2.5*weight;
}

//顯示結果
printf("\n你所購買的是%d級蘋果:\n",grade);
printf("實際重量:%g\n",weight);
printf("應付金額:%g\n",pay);

printf("交付金額:");
scanf("%f",&money);
printf("\n應找零錢:%g\n",money-pay);
printf("謝謝惠顧,再見!\n");
}
*/
/*
//字元串題目
#include<stdio.h>
#include<string.h>
void main()
{
char s1[100],s2[100];
puts("請輸入兩個字元串:");
gets(s1);
gets(s2);
strcat(s1,s2);
printf("連接後的結果:%s\n",s1);
int i,j;
char t;
i=0;
j=strlen(s1)-1;
while(i<=j)
{
t=s1[i];
s1[i]=s1[j];
s1[j]=t;
i++;
j--;
}
printf("反向後的結果:%s\n",s1);
printf("連接後的長度:%d\n",strlen(s1));
}
*/
//字元統計
#include<stdio.h>
void charc(char s[100])
{
int letters=0,numbers=0,spaces=0,others=0;
int i=0;
while(s[i]!='\0')
{
if(s[i]>='a' && s[i]<='z' || s[i]>='A' && s[i]<='Z')
letters++;
else if(s[i]>='0' && s[i]<='9')
numbers++;
else if(s[i]==' ')
spaces++;
else
others++;
i++;
}
printf("\n字母:%d個,數字:%d個,空格:%d個,其他:%d個\n",letters,numbers,spaces,others);
}
void main()
{
char str[100];
puts("請輸入字元串:");
gets(str);
charc(str);
}

C. 一道C語言編程題

#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
ints1[9][9],a,b,w,h,x,y,n;
voidgc(inta,intb,inthp,intm)
{
if(hp!=0)
{
if(s1[a][b]==3){if((m<n)||(n==0))n=m;}else
{
if(s1[a][b]==4)hp=6;
if(s1[a-1][b]!=0)gc(a-1,b,hp-1,m+1);
if(s1[a+1][b]!=0)gc(a+1,b,hp-1,m+1);
if(s1[a][b-1]!=0)gc(a,b-1,hp-1,m+1);
if(s1[a][b+1]!=0)gc(a,b+1,hp-1,m+1);
}
}
}
intmain()
{
scanf("%d%d",&w,&h);
for(a=1;a<=h;a++)
for(b=1;b<=w;b++){scanf("%d",&s1[a][b]);if(s1[a][b]==2)x=a;y=b;}
for(a=0;a<=w;a++){s1[0][a]=0;s1[h+1][a]=0;}
for(a=0;a<=h;a++){s1[a][0]=0;s1[a][w+1]=0;}
gc(x,y,6,0);
printf("%d",n);
return0;
}

D. C語言編程題,模擬的考題,求解答

#include<stdio.h>

intabc(inta[],intn);

intmain()

{

inti=0;

inta[]={1,2,3,4,5,6};

for(;i<=sizeof(a)/sizeof(int);++i)

{

printf("proctof%dis%d. ",i,abc(a,i));

}

return0;

}

intabc(inta[],intn)

{

if(n<=0)

{

returna[0];

}

else

{

returna[n-1]*abc(a,n-1);

}

}

運行截圖如下: