計算機程序設計C語言_第1頁
計算機程序設計C語言_第2頁
計算機程序設計C語言_第3頁
計算機程序設計C語言_第4頁
計算機程序設計C語言_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、全國信息技術水平考試計算機程序設計(C語言)輔導資料 第一部分 試題第一題 單項選擇題(在每小題列出的幾個選項中只有一個選項是符合題目要求的,請將正確選項前的字母填在題后的括號內。)1、在C語言中,如果下面的變量都是int類型,則輸出的結果是( )。sum=pad=5; pad=sum + + ,pad + + , + + pad;printf("%dn",paD、;A、7 B、6 C、5 D、42、以下程序的輸出結果是( )。# include <stdio.h>main() int i=010 , j = 10;printf("%d,%dn&quo

2、t;,+ +i , j - -); A、11,10 B、9,10 C、010,9 D、10,93、已知在ASCII代碼中,字母A的序號為65,以下程序的輸出的結果是( )。# include <stdio.h>main() char c1='A', c2='Y';printf("%d,%dn",c1,c2); A、因輸出格式不合法,輸出錯誤信息 B、65,90 C、A,Y D、65,894、指針s所指字符串的長度為( )。char *s=""NameAddressn";A、19 B、15 C、18 D

3、、說明不合法5、設有說明int(*ptr)m;其中的標識符ptr是( )。A、M個指向整型變量的指針B、指向M個整型變量的函數(shù)指針C、一個指向具有M個整型元素的一維數(shù)組的指針D、具有M個指針元素的一維指針數(shù)組,每個元素都只能指向整型量6、語句while(!E);中的條件!E等價于( )。A、E = = 0 B、E!=1 C、E!=0 D、E7、以下程序的輸出結果是( )。# include <stdio.h>main() printf("%dn",NULL); A、不確定的(因變量無定義) B、0 C、-1 D、18、以下函數(shù)調用語句中含有的實參個數(shù)為( )。f

4、unc(exp1,exp2),(exp3,exp4,exp5);A、1 B、2 C、4 D、59、設有以下語句:char a=3,b=6,c;c=ab<<2;則c的二進制值是( )。A、00011011 B、00010100 C、00011100 D、0001100010、下面的程序中第幾行有錯誤(每行程序前面的數(shù)字是行號)( )。1 #include <stdio.h>2 main()3 4 float a3=0,0;5 int i;6 for(i=0;i<3;i + + ) scanf("%d",&ai);7 for(i=1;i&l

5、t;3;i + + ) a0=a0+ai;8 printf("%fn",a0);9 A、沒有 B、第4行 C、第6行 D、第8行11、設有語句int a=3;則執(zhí)行了語句a+=a-=a*a;后,變量a的值是( )。A、3 B、0 C、9 D、-1212、以下的for循環(huán)( )。for(x=0,y=0; (y!=123)&&(x<4); x + + );A、是無限循環(huán) B、循環(huán)次數(shù)不定 C、執(zhí)行4次 D、執(zhí)行3次13、設有語句char a='72';則變量a( )。A、包含1個字符 B、包含2個字符 C、包含3個字符 D、說明不合法14、

6、以下程序的輸出結果是# include <stdio.h># include <math.h>main() int a=1,b=4,c=2;float x=10.5 , y=4.0 , z;z=(a+B、/c+sqrt(double)y)*1.2/c+x;printf("%fn",z); A、14.000000 B、015.400000 C、13.700000 D、14.90000015、sizeof(double)是( )。A、一種函數(shù)調用 B、一個雙精度型表達式C、一個整型表達式 D、一個不合法的表達式16、C語言中( )。A、不能使用do-wh

7、ile語句構成的循環(huán)B、do-while語句構成的循環(huán)必須用break語句才能退出C、do-while語句構成的循環(huán),當while語句中的表達式值為非零時結束循環(huán)D、do-while語句構成的循環(huán),當while語句中的表達式值為零時結束循環(huán)17、以下程序的輸出結果是( )。# include <stdio.h># include <string.h>main() char str12='s','t','r','i','n','g';printf("%dn"

8、,strlen(str); A、6 B、7 C、11 D、1218、以下程序的輸出結果是( )。# include <stdio.h>main() int a=2,c=5;printf("a=%d,b=%dn",a,C、; A、a=%2,b=%5 B、a=2,b=5 C、a=%d,b=%d D、a=%d,b=%d19、以下程序的輸出結果是( )。# include<stdio.h>main() int a ,b,d=241;a=d/100%9;b=(-1)&&(-1);printf("%d,%dn",a,B、; A

9、、6,1 B、2,1 C、6,0 D、2,020、以下程序的輸出結果是( )。# include <stdio.h>main() int i; for ( i=1;i<=5;i + + ) if ( i%2 ) printf("*");else continue; printf("#");printf("$n"); A、*#*#*#$ B、#*#*#*$ C、*#*#$ D、#*#*$21、以下for語句構成的循環(huán)執(zhí)行了多少次( )。# include <stdio.h># define N 2# def

10、ine M N+1# define NUM (M+1)*M/2main() int i , n=0;for ( i=1;i<=NUM;i + + );n + + ; printf("%d",n); printf("n"); A、5 B、6 C、8 D、922、設有以下語句,則不是對a數(shù)組元素的正確引用的選項是(其中0i<10)int a10=0,1,2,3,4,5,6,7,8,9, *p=a;A、ap-a B、*(&ai) C、pi D、*(*(a+i)23、有以下程序:( )。# include <stdio.h># d

11、efine N 6main() char cN; int i=0;for ( ;i<N ; ci=getchar () , i + + );for ( i=0 ; i<N ; putchar(ci) , i + + ); 輸入以下三行,每行輸入都是在第一列上 開始,<CR>代表一個回車符:a<CR>b<CR>cdef<CR>程序的輸出結果是A、abcdef B、a C、a D、a b b b c cd cdef d e f24、以下程序調用findmax函數(shù)求數(shù)組中值最大的元素在數(shù)組中的下標,請選擇填空( )。# include &l

12、t;stdio.h>findmax ( s , t , k )int *s , t , *k; int p; for(p=0,*k=p;p<t;p + + )if ( sp > s*k )_; main() int a10 , i , k ;for ( i=0 ; i<10 ; i + + ) scanf("%d",&ai);findmax ( a,10,&k );printf ( "%d,%dn" , k , ak ); A、k=p B、*k=p-s C、k=p-s D、*k=p25、有以下程序:( )。#inc

13、lude<stdio.h>union pw int i; char ch2; a;main() a.ch0=13; a.ch1=0; printf("%dn",a.i); 程序的輸出結果是(注意: ch0在低字節(jié),ch1在高字節(jié)。)A、13 B、14 C、208 D、20926、有以下程序:( )。# include<stdio.h>main() int c;while(c=getchar()!='n') switch(c-'2') case 0:case 1: putchar(c+4);case 2: putchar

14、(c+4);break;case 3: putchar(c+3);case 4: putchar(c+2);break; printf("n"); 從第一列開始輸入以下數(shù)據,<CR>代表一個回車符。2743<CR>程序的輸出結果是A、668977 B、668966 C、6677877 D、668876627、以下程序的輸出結果為( )。main() char *alpha6="ABCD","IJKL","MNOP","QRST","UVWX";char

15、 *p; int i;p=alpha;for(i=0;i<4;i + + ) printf("%s",pi); printf("n"); A、ABCDEFGHIJKL B、ABCD C、ABCDEFGHIJKLMNOP D、AEIM28、以下程序的輸出結果是( )。# include<stdio.h># define FUDGE(y) 2.84+y# define PR(A) printf("%d",(int)(A)# define PRINT1(A) PR(A);putchar('n')main()

16、int x=2; PRINT1(FUDGE(5)*x); A、11 B、12 C、13 D、1529、以下程序的輸出結果是( )。# include<stdio.h>main() int i=1,j=3;printf("%d",i + + ); int i=0; i+=j*2; printf("%d,%d",i,j); printf("%d,%dn",i,j); A、1,6,3,1,3 B、1,6,3,2,3 C、1,6,3,6,3 D、1,7,3,2,330、以下程序的輸出結果是( )。# include <std

17、io.h>main() int k=4,m=1,p;p=func(k,m); printf("%d,",p); p=func(k,m); printf("%dn",p);func(a,B)int a,b; static int m=0,i=2;i+=m+1; m=i+a+b; return(m); A、8,17 B、8,16 C、8,20 D、8,831、設有以下語句:char str412="aaa","bbbb","ccccc","dddddd",*strp4;in

18、t i; for(i=0;i<4;i + + )strpi=stri;不是對字符串的正確引用的選項是(其中0k<4)( )。A、strp B、strk C、strpk D、*strp32、設有以下語句: char str1="string",str28,*str3,*str4="string";則不是對庫函數(shù)strcpy的正確調用的選項是(庫函數(shù)用于復制字符串)A、strcpy(str1,"HELLO1"); B、strcpy(str2,"HELLO2"); C、strcpy(str3,"HE

19、LLO3"); D、strcpy(str4,"HELLO4");33、C語言中形參的缺省存儲類別是( )。A、自動(auto) B、靜態(tài)(statiC) C、寄存器(register) D、外部(extern)34、設有以下語句:struct st int n; struct st *next;static struct st a3=5,&a1,7,&a2,9,'0',*p;p=&a0;則下列哪一個表達式的值是6( )。A、p + + ->n B、p->n + + C、(*p).n + + D、+ + p->

20、;n35、以下四個程序中,哪一個不能對兩個整型變量的值進行交換( )。A、# include <stdio.h> B、# include <stdio.h>main() main() int a=10,b=20; swap(&a,&B); int a=10,b=20;printf("%d %dn",a,B); swap(&a,&B); swap(p,q) swap(p,q)int *p,*q; int p,q; int *t; int *t;t=(int )malloc(sizeof(int); t=*p;*p=*q;

21、*q=t;t=p;*p=*q;*q=*t; C、# include <stdio.h> D、# include<stdio.h>main() main() int *a,*b; int a=10,b=20;*a=10,*b=20; int x=&a,y=&b;swap(a,B); swap(x,y);printf("%d %dn",*a,*B); printf("%d %dn",a,B、; swap(p,q) swap(p,q)int *p,*q; int *p,*q;int t; int t;t=*p;*p=*q

22、;*q=t; t=*p;*p=*q;*q=t; 第二題 填空題1、以下C語言程序將磁盤中的一個文件復制到另一個文件中,兩個文件名在命令行中給出。#include <stdio.h>main(argc,argv)int argc; char *argv; FILE *f1,*f2; char ch;if(argc< 【1】 ) printf("Parameters missing!n"); exit(0); if( (f1=fopen(argv1,"r") = = NULL)|(f2=fopen(argv2,"w")

23、= = NULL) printf("Can not open file!n"); exit(0);while( 【2】 )fputc(fgetc(f1),f2);fclose(f1); fclose(f2); 2、以下程序求a數(shù)組中的所有素數(shù)的和,函數(shù)isprime用來判斷自變量是否為素數(shù)。素數(shù)是只能被1和本身整除且大于1的自然數(shù)。#include <stdio.h>main() int i,a10,*p=a,sum=0;printf("Enter 10 num:n");for(i=0;i<10;i + + ) scanf("

24、%d",&ai);for(i=0;i<10;i + + )if(isprime(*(p+ 【3】 ) = = 1) printf("%d",*(a+i); sum+=*(a+i); printf("nThe sum=%dn",sum); isprime(x)int x; int i; for(i=2;i<=x/2;i + + )if(x%i = = 0) return (0); 【4】 ; 3、以下程序調用invert函數(shù)按逆序重新放置a數(shù)組中元素的值。a數(shù)組中的值在main函數(shù)中讀入。#include <stdio.

25、h>#define N 10invert(s,i,j)int *s,i,j; int t; if(i<j) t=*(s+i); *(s+j)=(s+j);*(s+j)=t; invert(s, 【5】 ,j-1);main() int aN,i;for(i=0;i<N;i + + ) scanf("%d",a+ 【6】 );invert(a,0,N-1); for(i=0;i<N;i + + ) printf("%d",ai);printf("n"); 4、以下程序建立了一個帶有頭結點的單向鏈表,鏈表結點中的數(shù)

26、據通過鍵盤輸入,當輸入數(shù)據為-1時,表示輸入結束(鏈表頭結點的data 域不放數(shù)據,表空的條件是ph->next = = NULL).#include<stdio.h>struct list int data;struct list *next;【7】 creatlist() struct list *p,*q,*ph; int a;ph=(struct list *) malloc(sizeof(struct list);p=q=ph; printf("Input an integer number,enter -1 to end:n");scanf(&

27、quot;%d",&A):while(a!=-1) p=(struct list *)malloc(sizeof(struct list);p->data=a; q->next=p; 【8】 =p; scanf("%d",&A); p->next='0'; return(ph); main() struct list *head; head=creatlist();參考答案第一題 單選題1-5 CBDBC 6-10 ABBAC 11-15 DCACC 16-20 DADBA 21-25 CDCDA 26-30 AC

28、BBA31-35 ACADC 第二題 填空題:【1】3 【2】!feof(f1)或feof(f1)=0 【3】I 【4】return 1 或 return (1)【5】i+1 【6】 I 【7】 struct list * 【8】 q第二部分 程序題1、題目:打印出如下圖案(菱形) *程序分析:先把圖形分成兩部分來看待,前四行一個規(guī)律,后三行一個規(guī)律,利用雙重for循環(huán),第一層控制行,第二層控制列。程序源代碼:main() int i,j,k;for(i=0;i<=3;i+)for(j=0;j<=2-i;j+)printf(" ");for(k=0;k<=

29、2*i;k+)printf("*");printf("n");for(i=0;i<=2;i+)for(j=0;j<=i;j+)printf(" ");for(k=0;k<=4-2*i;k+)printf("*");printf("n");2、題目:將一個正整數(shù)分解質因數(shù)。例如:輸入90,打印出90=2*3*3*5。程序分析:對n進行分解質因數(shù),應先找到一個最小的質數(shù)k,然后按下述步驟完成:(1)如果這個質數(shù)恰等于n,則說明分解質因數(shù)的過程已經結束,打印出即可。(2)如果n<

30、;>k,但n能被k整除,則應打印出k的值,并用n除以k的商,作為新的正整數(shù)你n,重復執(zhí)行第一步。(3)如果n不能被k整除,則用k+1作為k的值,重復執(zhí)行第一步。程序源代碼:/* zheng int is divided yinshu*/main()int n,i;printf("nplease input a number:n");scanf("%d",&n);printf("%d=",n);for(i=2;i<=n;i+)while(n!=i)if(n%i=0) printf("%d*",i)

31、;n=n/i;elsebreak;printf("%d",n);3、題目:輸入一行字符,分別統(tǒng)計出其中英文字母、空格、數(shù)字和其它字符的個數(shù)。程序分析:利用while語句,條件為輸入的字符不為'n'.程序源代碼:#include "stdio.h"main()char c;int letters=0,space=0,digit=0,others=0;printf("please input some charactersn");while(c=getchar()!='n')if(c>='a&

32、#39;&&c<='z'|c>='A'&&c<='Z')letters+;else if(c=' ')space+;else if(c>='0'&&c<='9')digit+;elseothers+;printf("all in all:char=%d space=%d digit=%d others=%dn",letters,space,digit,others);4、題目:一個數(shù)如果恰好等于它的因子

33、之和,這個數(shù)就稱為“完數(shù)”。例如6=123.編程找出1000以內的所有完數(shù)。程序分析:請參照14程序源代碼:main()static int k10;int i,j,n,s;for(j=2;j<1000;j+)n=-1;s=j;for(i=1;i<j;i+)if(j%i)=0)n+;s=s-i;kn=i;if(s=0)printf("%d is a wanshu",j);for(i=0;i<n;i+)printf("%d,",ki);printf("%dn",kn);5、題目:從鍵盤輸入一個字符串,將小寫字母全部轉換

34、成大寫字母,然后輸出到一個磁盤文件“test”中保存。輸入的字符串以!結束。程序源代碼:#include "stdio.h"main()FILE *fp;char str100,filename10;int i=0;if(fp=fopen("test","w")=NULL) printf("cannot open the filen");exit(0);printf("please input a string:n");gets(str);while(stri!='!') if(

35、stri>='a'&&stri<='z')stri=stri-32;fputc(stri,fp);i+;fclose(fp);fp=fopen("test","r");fgets(str,strlen(str)+1,fp);printf("%sn",str);fclose(fp);6、題目:某個公司采用公用電話傳遞數(shù)據,數(shù)據是四位的整數(shù),在傳遞過程中是加密的,加密規(guī)則如下:每位數(shù)字都加上5,然后用和除以10的余數(shù)代替該數(shù)字,再將第一位和第四位交換,第二位和第三位交換。程序源代

36、碼:main()int a,i,aa4,t;scanf("%d",&a);aa0=a%10;aa1=a%100/10;aa2=a%1000/100;aa3=a/1000;for(i=0;i<=3;i+)aai+=5;aai%=10;for(i=0;i<=3/2;i+)t=aai;aai=aa3-i;aa3-i=t;for(i=3;i>=0;i-)printf("%d",aai);7、題目:兩個字符串連接程序程序源代碼:#include "stdio.h"main()char a="acegikm&q

37、uot;;char b="bdfhjlnpq";char c80,*p;int i=0,j=0,k=0;while(ai!='0'&&bj!='0')if (ai<bj) ck=ai;i+;Elseck=bj+;k+;ck='0';if(ai='0')p=b+j;elsep=a+i;strcat(c,p);puts(c);8、題目:海灘上有一堆桃子,五只猴子來分。第一只猴子把這堆桃子平均分為五份,多了一個,這只猴子把多的一個扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了

38、一個,它同樣把多的一個扔入海中,拿走了一份,第三、第四、第五只猴子都是這樣做的,問海灘上原來最少有多少個桃子?程序源代碼:main()int i,m,j,k,count;for(i=4;i<10000;i+=4) count=0;m=i;for(k=0;k<5;k+)j=i/4*5+1;i=j;if(j%4=0)count+;elsebreak;i=m;if(count=4)printf("%dn",count);break;9、題目:編寫一個函數(shù),輸入n為偶數(shù)時,調用函數(shù)求1/2+1/4+.+1/n,當輸入n為奇數(shù)時,調用函數(shù)1/1+1/3+.+1/n(利用指

39、針函數(shù))程序源代碼:main()#include "stdio.h"main()float peven(),podd(),dcall();float sum;int n;while (1)scanf("%d",&n);if(n>1)break;if(n%2=0)printf("Even=");sum=dcall(peven,n);Elseprintf("Odd=");sum=dcall(podd,n);printf("%f",sum);float peven(int n)float

40、 s;int i;s=1;for(i=2;i<=n;i+=2)s+=1/(float)i;return(s);float podd(n)int n;float s;int i;s=0;for(i=1;i<=n;i+=2)s+=1/(float)i;return(s);float dcall(fp,n)float (*fp)();int n;float s;s=(*fp)(n);return(s);10、題目:打印出楊輝三角形(要求打印出10行如下圖)程序分析:11 11 2 11 3 3 11 4 6 4 11 5 10105 1程序源代碼:main()int i,j;int a1

41、010;printf("n");for(i=0;i<10;i+)ai0=1;aii=1;for(i=2;i<10;i+)for(j=1;j<i;j+)aij=ai-1j-1+ai-1j;for(i=0;i<10;i+)for(j=0;j<=i;j+)printf("%5d",aij);printf("n");11、題目:畫橢圓ellipse程序源代碼:#include "stdio.h"#include "graphics.h"#include "coni

42、o.h"main()int x=360,y=160,driver=VGA,mode=VGAHI;int num=20,i;int top,bottom;initgraph(&driver,&mode,"");top=y-30;bottom=y-30;for(i=0;i<num;i+)ellipse(250,250,0,360,top,bottom);top-=5;bottom+=5;getch();12、題目:畫圖,學用circle畫圓形。程序源代碼:/*circle*/#include "graphics.h"main()int driver,mode,i;float j=1,k=1;driver=VGA;mode=VGAHI;initgraph(&driver,&mode,"");setbkcolor(YELLOW);for(i=0;i<=25;i+)setcolo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論