c语言考试试题(C language exam)_第1页
c语言考试试题(C language exam)_第2页
c语言考试试题(C language exam)_第3页
c语言考试试题(C language exam)_第4页
c语言考试试题(C language exam)_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、c语言考试试题(C language exam)1) from the keyboard input six integers, the even number of statistics.(main)Int a6, I, s=0;(clrscr);For (i=0; i6; i+)Printf (please input a%d=, I);Scanf (%d, &ai);If (ai%2=0)S+;Printf (s=%dn, s);2) input 10 to a referee players score, the final score for the player.(main)Int

2、 a10, I, Max, min, sum=0;(clrscr);Float aver;For (i=0; i10; i+)Printf (please input a%d=, I);Scanf (%d, &ai);Max=a0; min=a0;For (i=0; imax) max=ai;If (aimin) min=ai;Sum=sum+ai;Aver= (sum-max-min) /8.0;Printf (aver=%fn, aver);3) given an array of a10=23, -8,1,90, -45,2,34,0,39, -11, and the minimum o

3、utput array element position.(main)Int a10=23, -8,1,90, -45,2,34,0,39, -11, I, min, loc;(clrscr);Min=a0; loc=0;For (i=0; i10; i+)If (aimin)Min=ai;Loc=i;Printf (min=%d loc=%dn, min, LOC);4) enter a number from the keyboard, determine whether it is in the -21 array 28,12,3,10,9, and output the corresp

4、onding prompt.(main)Int a6=28,12,3,10,9, -21;Int i, N, f=0;(clrscr);Printf (please input n:);Scanf (%d, &n);For (i=0; i6; i+)If (ai=n)F=1;Break;If (f=0)Printf (no found!);ElsePrintf (found%d location is%dn, N, I);6) input 6 numbers from the keyboard, using bubble sort according to the output from bi

5、g to small order.(main)Int i, J, t;Int a6;For (i=0; i6; i+)Printf (please input a%d=, I);Scanf (%d, &ai);For (i=0; i5; i+)For (j=0; j5-i; j+)If (ajaj+1)T=aj;Aj=aj+1;Aj+1=t;For (i=0; i6; i+)Printf (%d, ai);8) from the keyboard input A33, output to its transpose.(main)N output Yang Hui triangle.#defin

6、e N 11(main)Int aNN, I, j;For (i=1; iN; i+)Ai1=1;Aii=1;For (i=3; iN; i+)For (j=2; j=i-1; j+)Aij=ai-1j-1+ai-1j;For (i=1; iN; i+)For (j=1; jmax2) max2=y;If (zmax2) max2=z;Return max2;15. programming from the keyboard input radius, circumference and area of output, write the function for perimeter and

7、area.#define PI 3.14(main)Float C1 (float R);Float S1 (float R);Float R, C, s;(clrscr);Printf (please input r:);Scanf (%f, &r);C=c1 (R);S=s1 (R);Printf (c=%f s=%fn, C, s);Float C1 (float R)Float x;X=2*pi*r;Return x;Float S1 (float R)Float y;Y=pi*r*r;Return y;16. input from a even greater than 6, the

8、 number is decomposed into the sum of two primes, asked to write a function to determine whether it is prime.Int test (int x);(main)Int n, a, b;Printf (please input n:);Scanf (%d, n);For (a=1; an/2; a+)B=n-a;If (test (a) =1&test (b) =1)Printf (%d=%d+%dn, N, a, B);Int test (int x)Int i, f=0;For (i=2;

9、 ix-1; i+)If (x%i=0)F=0;ElseF=1;Return f;17. programming for S=3! +5! +8!, as part of the preparation of factorial function.(main)Long fact (int n);Long s;S=fact (3) +fact (5) +fact (8);Printf (s=%ldn, s);Long fact (int n)Int i;Long m=1;For (i=1; i=n;我+ +)M = M *我;返回M;18。从键盘输入输出N,N!(要求使用递归算法)main()长

10、的事实(int);长的N、S;clrscr();printf(“请输入N:”);scanf(“%ld”,和N);S =事实(N);printf(“%ld!= %ld”,N,S);长的事实(int n)长米;如果(n = 1)M = 1;其他的M = N *(N-1)事实;返回M;19。从键盘输入N,编程输出斐波纳契数列(1 2 3 5 8 13 34 .)的前N项,要求编写一使用递归求斐波纳契数列第N项的函数。int FIB(int n);main()int n,f;printf(“请输入N:”);scanf(“%d”,和N);F = FIB(N);printf(“FIB(%)= %dn”,N

11、,F);int FIB(int n)int m;如果(n = 1)M = 1;如果(n = 2)M = 2;如果(N3)M = FIB(n-1)+ FIB(n-2);返回M;20。编程求S = 1/1!+(1 + 2)/ 2!+(1 + 2 + 3)/ 3!+(1 + 2 + 3 + 10)/ 10!,要求把求阶乘部分和求和部分编写成两个函数,并在主函数中调用两个函数。int和(int n);浮动的事实(int n);main()浮S = 0;int i;clrscr();为(i = 1;i = 10;i+)S = S +和(我)/事实(我);printf(“S = % f n,s);int和

12、(int n)int m = 0,我;为(i = 1;i = n;i+)M = M +我;返回M;浮动的事实(int n)int i;float f = 1;为(i = 1;i = n;i+)F = F *我;返回F;21。猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第十天早上想再吃时,见只剩下一个桃子了,问,第一天共摘了多少个桃子?长f(int);main()int n;长x;clrscr();X = F(1);printf(“%ld”,x);长f(int n)长米;如果(n =

13、10)M = 1;其他的M = 2 *(F(n-1)+ 1);返回M;22。输入一和B两个整数,按先大后小的顺序输出一和B.main()int * P1,P2 P *,*,A,B;printf(“请输入A和B:“);scanf(“%d,%d”,&,& B);P1 = &;P2 = & B;如果(a b)P = P1;P1 = P2;P2 = P;printf(“= %d,B = %dn”,* * P1,P2);返回0;用函数处理上述题,且用指针类型变量的数据作函数变量。#包括main()无效的交换(int * int * P1,P2);a,b;clrscr();pointer_1 int *,

14、* pointer_2;printf(“请输入A,B:”);scanf(“%d,%d”,&,& B);pointer_1 = &;pointer_2 = & B;如果(a b)互换(pointer_1,pointer_2);printf(“最大= %d分钟= %d”,max,min);无效的交换(int * int * P1,P2)int变量;温度=P1;* P1 =P2;* P2 =温度;23。输出所有元素及其地址。main()漂浮的我,一个 6 = 1 2 3 4 5 6 ;浮* P;clrscr();P =一;为(i = 0;i 6;i+)printf(“ % % F = F n”,I、

15、P 我);getch();24排序排序(int *);#包括main()在我,一个 8 = 4,2,- 7,11,5234,75,28 ;clrscr();分类(一);为(i = 0;i 8;i+)printf(“%d”,一个我);排序(int * p)int i,j,t;为(i = 0;i 7;i+)为(J = 0;J 7-I;j+)如果(PP J J + 1)T = P J.;P J J + 1 = P;P = t + 1 研究J.;24。判断一个数是否在数组中。#包括国际main()int i,f = 0,x;a 6 = 21 28,12,3,10,9;printf(“请输入X:”);s

16、canf(“%d”,和X);为(i = 0;i 6;i+)如果(一个我 = = X)F = 1;打破;如果(F = = 0)printf(“没有找到!”);else printf(“%d,LOC %dn”,一个我,我);返回0;25。编程从键盘输入两个正整数A,B,求一的B次方。要求编写一个函数长mypow(int,int b)。长mypow(int int);a,b;长的;clrscr();printf(“请输入A,B:”);scanf(“%d,%d”,&,& B);S = mypow(A,B);printf(“S = %ld”,S);长mypow(int,int n)长T;如果(a = 1

17、)T = M;其他mypow T =(M,n-1)M;返回T;26。从键盘输入两个数,交换他们的值后输出,编写互换函数。互换(int,int)无效;main()a,b;printf(“请输入A,B:”);scanf(“%d,%d”,&,& B);互换(A,B);printf(“= %d B = %dn”,A,B);无效的交换(x,y)int t;T = x;x = y;Y = T;无效的交换(int,int *);main()a,b,* * P1,P2;* P1和P2 = =,*和B;printf(“请输入A,B:”);scanf(“%d,%d”,P1,P2);互换(P1,P2);printf(“= %d B = %dn”,A,B);无效的交换(int x,int y)int * T;* T =;* X = Y;* = * T;27。把给定的数按照从小到大的顺序排序。排序(int *);main()在我,一个 8 = 4,2,- 7,11,5234,75,28 ;分类(一);为(i = 0;i 8;i+)printf(“%d”,一个我);排序(int * p)int t,我;为(i = 0;i 8;i+)如果(28。把给定的数组倒叙输出。29。请编写求给定字符窜长度的函数:mystrlen(char * p)。国际mystrle

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论