2008年北航C语言期末试题

合集下载

北航在线作业C语言答案1

北航在线作业C语言答案1
第3题 十六进制数100转换成十进制数是:
A、1024
B、512
C、256
D、128
答案:C
第4题 C语言中的注释语句用什么标示?
A、/* */
B、//
C、;
D、#
答转换成十六进制数是:
A、64
B、63
C、100
D、144
答案:A
第6题 常数的书写格式决定了常数的类型和值,0x1011是:
A、8进制整型常量
B、字符常量
C、16进制整型常数
D、2进制整型常数
答案:C
第7题 C语言中函数的返回语句是___。
单项选择题
第1题 C语言从哪个函数开始执行?
A、main
B、begin
C、start
D、go
答案:A
第2题 常用的C语言输出函数是___。
A、scanf
B、print
C、printf
D、input
答案:C
正确
错误
答案:正确
第18题 long能表示的最小数是-2^31。
正确
错误
答案:正确
第19题 实型数据在内存中是以指数形式存储的。
正确
错误
答案:正确
第20题 每一个C程序都必须有一个main函数。
正确
正确
错误
答案:正确
第12题 实数只有十进制小数形式和指数形式两种。
正确
错误
答案:正确
第13题 字符数据只占一个字节,只能存放0~255范围内的整数。
正确
错误
答案:正确

C语言程序设计2007~2008学年第二学期期末考试试卷(A)

C语言程序设计2007~2008学年第二学期期末考试试卷(A)
时,其数组下标的数据类型允许是

整型常量整型表达式 整型常量或整型表达式任何类型的表达式

若二维数组有列,则在前的元素个数为

、 以下叙述中不正确的是。
在中,函数中的自动变量可以赋初值,每调用一次,赋一次初值 在中,在调用函数时,实参和对应形参在类型上只需赋值兼容 在中,外部变量的隐含类别是自动存储类别 在中,函数形参可以说明为变量
、 以下程序运行后输出结果是 () () ()
大厦白蚁预防工程承包合同合同签订版
、 以下程序运行后输出结果是 ❖❖
、 以下程序运行后输出结果是
四、 程序设计题共分
得分 评阅人
某班级学生进行百米跑测试,规定成绩在秒以内(含秒)为优秀,在 秒以上至秒为达标,在秒以上为不达标,编一程序,从键盘上输入每个 人的成绩,以作为输入变量,并以小于的任何数作为终止标志,分别用变量 和统计出成绩为优秀、达标和不达标的人数。
、 以下正确的函数原型语句是。
、 循环体至少被执行一次的语句为。
循环循环循环 任一种循环
、 在下面循环语句中内层循环体语句的执行总次数为。
、 函数调用不可以。
出现在一个表达式中 出现在执行语句中 作为一个函数的实参 作为一个函数的形参
大厦白蚁预防工程承包合同合同签订版
、 将两个字符串连接起来组成一个字符串时,选用函数。
大厦白蚁预防工程承包合同合同签订版
试卷编号:卷
课程编号:课程名称:语言程序设计考试形式: 闭卷
适用班级:全校非计算机专业姓名:学号: 班级:
学院:专业: 考试日期:、、
题号 一 二 三 四 五 六 七 八 九 十 总分 累分人
题分 得分
签 名
考生注意事项:、本试卷共页,请查看试卷中是否有缺页或破损。如有立 即举手报告以便更换。

北京航空航天大学《C语言程序设计》试卷

北京航空航天大学《C语言程序设计》试卷

北京航空航天大学《C语言程序设计》课程考试试卷注意事项: 1、本试卷满分100分;考试时间:90分钟;考试形式:开卷2、请将答案一律写在答题纸上,试卷上作答无效3、考试结束后,考生将试卷及答题纸一并交回4、请将条形码贴在答题纸的指定位置学习中心______________姓名____________学号____________一、单项选择题(本大题共10小题,每小题2分,共20分)1、设有定义语句“char s[]=”123”;”,则表达式“s[3]”的值是______。

()A.' 1' B.'3'C.'\0' D.存在语法错误2、凡是函数中未指定存储类别的局部变量,其隐含的存储类别为______。

()A.自动(auto) B.静态(static)C.外部(extern) D.寄存器(register)3、已知:char w; int x; float y; double z;,则表达式w*x+z-y结果的类型是______。

()A.float B.charC.int D.double4、当声明一个结构变量时,系统分配给它的内存是______。

()A.各成员所需内存量的总和B.结构中第一个成员所需内存量C.成员中占内存量最大者所需的容量D.结构中最后一个成员所需内存量5、C语言中的简单数据类型包括______。

()A.整型、实型、逻辑型B.整型、实型、字符型C.整型、字符型、逻辑型D.整型、实型、逻辑型、字符型6、合法的数组说明语句是______。

()A.int a[]="string";B.int a[]={0,1,2,3,4,5};C.char a="string";D.char a[5]={'0','1','2','3','4','5,};7、定义int i=1;,执行语句while(i++<5);后,i的值为______。

2007年北航C语言期末试题(修改版)

2007年北航C语言期末试题(修改版)

《 C 程序设计》期末考试卷一、选择题 (20分) 1, 下列运算符中最高优先级的运算符是A) && B) % C) -= D)!2, 对定义语句int a[]={1,2,3,4,5,6,7,8,9,10},*p=a,i=5;数组元素地址的正确表示是A)&(a+1) B)a++ C)&p D)&p[i]3, 以下结构定义,请指出不正确赋值语句是struct date{int month;int day;int year;};struct student{int num;char name[20];char sex;struct date birthday;float score;char addr[30];}stu1,stu2;A) stu1.num=10; B) stu1.score+=stu2.score;C) stu1=stu2; D) stu1.birthday.month=12;4,以下程序:#include <stdio.h>void main(){FILE *fp;fp1=fopen(“f1.txt”,”w”);fprintf(fp,”abc”);fclose(fp);}若文本文件f1 .txt中原有内容为good,则运行以下程序后文件f1.txt中的内容为A) abc B)abcd C) goodabc D) abcgood5,以下程序的运行结果是int f(int i){static int n=1;return n=n*i;}int main(){for (i=1;i<5;i++) printf(“%3d”,f(i));printf(“\n”);}A)1 2 3 4 B)1 2 6 24 C)1 2 4 6 D)1 3 6 24二、填空题 (30分)1, 若有定义double x; (5分)(1)使指针p可以指向变量x的定义语句是_________________(2)使指针p指向变量x的赋值语句是________________(3)通过指针p给变量x读入值的scanf函数调用语句是________________(4)通过指针p给变量x赋值语句是___________________(5) 通过指针p输出x的值的语句是____________________2,以下函数用以求x的y次方。

北航c语言期末试题

北航c语言期末试题

PARTⅠ: GIVE A DECISION. circle …T‟for true and …F‟for false(10marks, 1 mark per point)1.The value of the expression 8==8==8 is 1. T F2. An array name is the address of the first element of the array. T F3. typedef merely adds a new name for some existing type. T F4. Evaluate !(1 &&0 ||!1) as true or false T F5. The null character …\0‟ terminates all character strings. T F6. The output of the following is *successful----- *main() {printf(“*%15.10s*”,” successfully”);}T F7. Assuming enum week { MON, TUE=2, WES, THUR, FRI, SAT, SUN};the value of SAT is 6 . T F8. In C, the value of the expression 9/8 is 0 T F9. For an array declaration a[][2]={0,1,2,3,4,5,6,7,8}, the row size is 4. T F10. Automatic and register variables have undefined initial values. T FPARTⅡ: SINGLE CHOICE QUESTIONS(40marks, 2marks per question)1. The C program consists of ______________.A)a main function and some subroutines B)functionsC)procedures D)subroutines.2. Which of the following constant is invalid?______________A) 0818 B) 2.5e-2 C) 2f D) 0xA53. What does strcat (an_array, “this”); do?_______________A) finds “this” in an_arrayB) adds “this” to the end of an_arrayC) compares an_array and “this”D) copies “this” into an _array4. Which operator has the highest precedence?____________A.+= B.++ C.? : D.[ ]5. Which of the following operator can be used as an unary-operator? ___________A.+= B.% C.* D./6. Which one is wrong if it is used as a character constant? _____________A.”1” B.‟1‟ C.1 D.‟\n‟7. According to the declaration: int a[10], *p=&a[2]; the last element of the array a is ______.A.a[10] B.p[9] C.p[8] D.p[7]switch(grade){ case‘A’:printf(“*”);case‘B’:printf(“**”);case‘C’:printf(“***”);case‘D’:printf(“****”);default :printf(“#”);}A) *** B) **** C) ***# D) *******#9. For the variable names below, which group is the one whose all variable names are invalid?__________A)Printf B)sort_1row string_to_floatIF EnumC) register D) DOUBLE1P book_pric et.abc A2B10 As we know that a library function double acos(double x) )1,1(-x which is included in∈“math.h”. which one of the following works properly?___________A #include “stdio.h” int y=acos(2);B #inlcude “math.h” int z; z=acos(0.5);C #include “math.h” double y,x; y=acos(x);D #include “math.h” int x,z; z=acos(x=0.3);11. Assuming that the user of a program is asked to enter a day number (1-7) into an integervariable called day. Which of the following while loops is valid?____________A. while (day >= 1 || day <= 7){printf("ERROR 1 - 7 only, enter again: ");scanf(“%d”, &day);}B. while (day >= 1 && day <= 7){printf("ERROR 1 - 7 only, enter again: ");scanf(“%d”, &day);}C. while (day < 1 || day > 7){printf("ERROR 1 - 7 only, enter again: ");scanf(“%d”, &day);}D. while (day <= 1 || day >= 7){printf("ERROR 1 - 7 only, enter again: ");scanf(“%d”, &day);}12. Which one is wrong? ___________A.char str[10]; str="string"; B.char str[ ]="string";C.char *p="string"; D.char *p; p="string";13. According to the declaration: int p[5], *a[5]; Which of the following expression is correct?______________A.p=a B.p[0]=a C.*(a+1)=p D.a[0]=214. Predict what gets printed: __ .void swap(int *a, int *b){ int *k;k=a; a=b; b=k;}main(){ int a=3, b=6, *x=&a, *y=&b;swap(x,y);printf("%d %d", a, b);}A) 6 3 B) 3 6 C) compiling error D) 0 015. Predict what gets printed: _________________# include <stdio. h>int a=10, b, x, y;void num (){ int a=15,b=10;x = a - b; y = a + b;printf("%d, %d\n”, x, y):}main (){ a= 7,b =5; num (); }A) not for sure B) 12,2 C) 5,25 D) 0,2016. Assuming #define sum(a, b) a + b predict the value of: 5 * sum(3 + 1, 2) ____________.A. 30B. 18C. 22D. none of the above17. What is the main problem with the following: __________int *ip;for (*ip = 0; *ip < 5; *ip++);A) Nothing is wrong.B) It dereferences(间接引用) an uninitialized pointer.C) It does nothing useful.D) It contains implementation dependent problem(s).18. Predict the output from: __________if (5 < 4)if (6 > 5)putchar('1');else if (4 > 3)putchar('2');elseputchar('3');putchar('4');A) 4B) 2C) 24D) 4 or 24, depending upon the implementation.19.What is the main problem with the following?______________①main( )②{ int a[10],i;③for (i=0;i<10;i++)④scanf (“%d”,a[i]);⑤for (i=0;i<10;i++)⑥a[i]= a[i+1];⑦}A) Nothing is wrong.B) Line④is wrong.C) Line⑥is wrong.D) Both line④and ⑥are wrong.20. The program segment (程序段) below reverses(逆序) the string s in the place, which one is written correctly?_______________A)for (i = 0, j = strlen(s); i < j; i++, j--)c = s[i], s[i] = s[j], s[j] = c;B) for (i = 0, j = strlen(s)-1; i < j; i++, j--)c = s[i], s[i] = s[j], s[j] = c;C)for (i = 0, j = strlen(s)-1; i < j; i++, j--)c = s[i]; s[i] = s[j]; s[j] = c;D) for (i = 0, j = strlen(s); i < j; i++, j--)c = s[i]; s[i] = s[j]; s[j] = c;PAR TⅢ: FILL IN THE BLANKS (20marks, 1 mark per blank)1. Write a conditional expression to calculate the maximum of x and y.___________.2. Predict the value of the expression ~ (10^2) &7 ___________.3. Predict what gets printed______________.char *st[ ]={"ONE","TWO","THREE","FOUR"};printf("%s, %c\n", *(st+2), **st+1);4. Predict what gets printed._____________int f (int x){if(x<=1) return 1;else return f(x-1)+f(x-2);}void main ( ){ printf("%d", f(4));}5. After running the program below , if the output (z)is 9.00,please predict the initial value of x. main(){ int a=7, b=2;float x= __________ , y=1.1,z;z=a/2+b*x/y+1/2;printf("%.2f\n", z );}6. Here is a declaration:union {unsigned long l_num;unsigned char c_num[4];} d;Assuming that d.l_num=0x36c3a1f, what is the value of d.c_num[2]?__________.How many bytes does the variable d hold in the memory? __________7. Predict what gets printed: __ .main(){ int x;for (x=1; x<10; x++){ if (x<3) continue;x*=2 ;printf(“#”);}}9. Predict what gets printed: _ ..void fun(){ static int a=1;a*=a+1; printf(“%d,”,a);}main(){ int cc;for(cc=1;cc<4;cc++) fun();}10. Predict what gets printed:______________.main(){ int array [] = {2, 8, 3, 11, 13, 2, 8, 2};int k;int total = 0;for ( k = 0; k < 8; k++ ) {if ( array [k] % 2) break;total += array [k];}printf ( “%d ”, total );}11. Assuming int a[3][3]={2,4,6,8,10,12,14,16}; the value of *(a[2]+2) is ___________.12. Here is a binary search function that decides if a particular value occurs in the sorted array v.int binsearch(int x, int v[], int n) /* binsearch:find x in v[0] <= v[1] <= ... <= v[n-1] */ { int low, high, mid;low = 0; high = n - 1;while (low<high) {mid = (low+high)/2;if (____________) high = mid -1 ;else if (____________) low = mid+1;else /* found match */return mid;}return -1; /* no match */}13. Function itoa: convert n to characters in s , fill in the blanksvoid itoa(int n, char s[]){ int i, sign;if ((sign = n) < 0) /* record sign */n = -n; /* make n positive */i = 0;do { /* generate digits in reverse order */s[i++] = _______________; /* get next digit */} while ((__________) > 0); /* delete it */if (sign < 0)s[i++] = '-';s[i] = '\0';reverse(s);}8. Write the prototype(原型) for the following C functionFunction name : maxReturn data type: intInput data types: two input values of type int________________________22. Predict what gets printed:_________________.void melon (int g, int * h);int main (void){ int a = 1, b = 2;melon ( a, &b );printf ( "a = %d, b = %d", a, b );}void melon (int b, int * c){ b++;*c = *c + b;}23. Here is a function month_day which converts the day of the year into the day of month.void month_day(int year, int yearday, int *pmonth, int *pday){ static int day_tab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};int k, leap;leap = year % 4==0 && year % 100 != 0 || year % 400 == 0;for(k=1; yearday > day_tab[leap][k]; k++)____________________;*pmonth = _____________ ;*pday = yearday;}25. The program below calculates the value of s = 1/1! + 1/2! + 1/3! + ……+ 1/n!. Assuming that the input is positive(n>0), fill in the blanks to complete the program.#include <stdio.h>void main( ){ int j, k, n;float f, s;scanf("%d", &n);s=0;for (k=1 ; k<=n; k++){f=1 ;for(j=1; j<=k; j++)____________ ;s=s+1.0/f;}printf("sum=%f\n", s);}PART Ⅲ: PROGRAMMING(30marks)1.Write a program to print all the numbers which are between 1 to 100, can be divided by 6 andwhose unit‟s places(个位) are 2. (10marks)2. Write a function to change a matrix (矩阵) with m rows and n columns into the matrix withn rows and m columns. (10 marks)3.Create a structure called stud that includes 4 pieces of information as data members——student‟s number and three subject scores(学号和三科成绩),Suppose there are 6 students whose information are {1001, 88,90,74} , {1002,69,66,89}, {1003,87,74,70}, {1004,60,80,66}, {1005,95,84,87}, {1006,90,93,82}, write a program to do the following :ⅰ) print out every students‟ information and their average scores.ⅱ) Sort the average scores in descending order(降序).(10 marks)。

北航《C语言程序设计》答案

北航《C语言程序设计》答案

北航《C语言程序设计》答案北航《c语言程序设计》在线作业一单项选择和判断问题一、单选题(共15道试题,共60分。

)1.以下叙述中正确的是a、预处理命令行必须位于源文件的开头。

B.源文件的一行上可以有多个预处理命令。

C.宏名称必须用大写字母表示d.宏替换不占用程序的运行时间正确答案:d2.以下选项试图描述一个新的类型名称,其中正确的名称是a.typedefv1int;b、typedefv2=int;c、类型定义tv3;d、 typedefv4:int;正确答案:C3.c语言对嵌套if语句的规定是:else总是与()配对。

a.其之前最近的ifb.第一个ifc、其上一个最近的IFD没有其他的,如果具有相同的缩进位置,正确答案是:c4.已知:#definen3;执行语句i=n*3;后,i=_______.a.3b.6c.9d、以上这些都不正确。

正确答案:C5.以下选项中可作为c语言合法常量的是a.-8b.-080c.-8e1.0d.-80.0e正确答案:a6.以下不正确的c语言标识符是_____。

a.abcb.abcc.a_bcd.ab.c正确答案:D7.数组int**a[3][4]占据多大空间a、 64b。

12c。

48d。

一百二十八正确答案:c8.已知:intx,a,B;以下选项中错误的if语句是_;。

()a.if(a=b)x++;b.if (a)=正确答案:b9.以下可以正确表示字符类型常量为___。

a、 \b。

?Tc、 \d.297正确答案:b10.表达式:10=9的值为()a.trueb非零值c.0d一正确答案:d11.在C语言中,形式参数的默认存储类型是()a.autob registerc。

静力学。

外人正确答案:a12.假设在C语言中,一个int数据在内存中占用2个字节,那么无符号int数据的值范围是_u。

a、 0~255b。

0~32767c。

0~65535d.0~2147483647正确答案:c13.有以下声明:intb;charc[10];,正确的输入语句是a.Scanf(\b.Scanf(\c.Scanf(\d.Scanf)(\正确答案:b)14.为了避免嵌套的条件分支语句的二义性,c语言规定,c程序中的else总是与()组成配对关系。

2008级C语言期末机考试卷及答案

2008级C语言期末机考试卷及答案

安徽大学2008----2009学年第二学期C语言程序设计期末机考试题一、单项选择题(30分,每题2分)每小题的四个选项中只有一个符合题目要求,请将正确选项前字母填在括号中。

1.若int a[][3]={1,2,3,4,5,6};则a[1][0]的值是【______】。

AA. 4B. 2C. 1D. 52.执行下列程序段后,变量k的值是【______】。

Aint k=3, s[2];s[0]=k;k = s[1]*10;A)不确定B)0C)10 D)303.执行下列程序段后,变量k的值是【______】。

Cint k=3, s[2]={1};s[0]=k;k = s[1]+10;A)不确定B)0C)10 D)304.下面程序的输出结果是【______】。

C#include <stdio.h>void main(void){int i, a[10];for(i=9;i>=0; i--)a[i]=10-i;printf("%d%d%d\n",a[2],a[5],a[8]);}A)258 B)741C)852 D)3695.下面程序的输出结果是【______】。

B#include <stdio.h>void main(void){int a[3][3]={1,2,3,4,5,6,7,8,9},i;for(i=0;i<3; i++)printf("%d ",a[i][2-i]);}A)1 5 9 B)3 5 7C)1 4 7 D)3 6 96.下面程序的输出结果是【______】。

C#include "stdio.h"void fun(int a[]){int i;for(j=0;j<5; j++)a[j]=j;}void main(void){int num[]={5,6,7,8,9}, i;fun(num);for(i=0;i<5; i++)printf("%d ", num[i]);}A. 56789B. 98765C. 01234D. 432107.下面程序的输出结果是【______】。

2008级信息类C语言程序设计期末A卷

2008级信息类C语言程序设计期末A卷

5、以下循环语句可以正确终止的是 C 。 A、int i = 100; B、for( ; ;); while( 1 ) { i = i++ % 100; if( i > 100 ) break; } C、int k = 32764; do { k++;k++; }while( k > 0 ); 6、sizeof ( float )是 B 。 A、一个双精度型表达式 C、一种函数调用 D、int s = 32764; while( ( s++ % 2) || ( s % 2 ) ) s++;
2、编程实现,任意输入一个偶数 n,将它们分解为两个 素数之和。(10分) 输出形式为 * = * + *,例如输入12,输出:12 = 7 + 5。
测试用例: 输入 1.2↙ 2.12↙ 3.124↙ 4.1234↙ 5.20000↙
输出 2 = 1 + 1↙ 12 = 7 + 5↙ (公开) 124 = 11 + 113↙ 1234 = 3 + 1231↙ 20000 = 3 + 19997↙
三、上机编写程序题(共40分)
1、编程实现,输入顶行字符和图形的高,在屏幕上输出如 图所示的图形(下例顶行字符为’A’,图形的高为5)。 (10分) A BCD EFGHI JKLMNOP QRSTUVWXY
测试用例: 输入 1.3 Z↙
2.1 B↙ 3.4 M↙
4.5 A↙
5.0 A↙
输出 Z↙ A B C↙ D E F G H↙ B↙ M↙ N O P↙ Q R S T U↙ V W X Y Z A B↙ A↙ (公开) B C D↙ E F G H I↙ J K L M N O P↙ Q R S T U V W X Y↙ ↙
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一、阅读下列程序并回答问题(20分,每题5分)
1、若有以下程序
#include <stdio.h>
void main()
{
char a[20];
scanf(“%s”,a);
printf(“%s\n”,a);
}
从键盘上输入19个字符:one world one dream, 则输出为。

A. one world one dream
B. one world one
C. one world
D. one
2、有一函数关系如下:
x-1 x<0
y= x x=0
x+1 x>0
下列程序能够正确表示上述关系的是__________________________。

A. y=x+1;
B. y=x-1;
if (x>=0) if (x!=0)
if (x==0) y=x; if (x>0) y=x+1;
else y=x-1; else y=x;
C. if (x<=0)
D. y=x;
if (x<0) y=x-1; if (x<=0)
else y=x; if (x<0) y=x-1;
else y=x+1; else y=x+1;
3、请写出以下程序的输出结果:______________________________。

#include <stdio.h>
void swap(int *ptr1,int *ptr2)
{
int i;
i=*ptr1;
*ptr=*ptr2;
*ptr2=i;
}
void exchange(int *q1,int *q2,int *q3)
{
if (*q1<*q2) swap(q1,q2);
if (*q1<*q3) swap(q1,q3);
if (*q2<*q3) swap(q2,q3);
}
void main()
{
int a,b,c;
a=9,b=3,c=12;
exchange(&a,&b,&c);
printf(“a=%d,b=%d,c=%d\n”,a,b,c);
}
4、若有以下程序
#include <stdio.h>
int sum(int k);
void main()
{
int s,i;
for (i=1;i<=10;i++) s=sum(i);
printf(“s=%d\n”,s);
}
int sum(int k)
{
static int x=0;
x+=k;
return (x);
}
(1)上述程序的功能是什么?运行结果是什么?
(2)若将sum()函数中的变量说明语句static int x=0;改为int x=0;,程序的运行结果是又什么?为什么?
二、程序填空题(20分,每题5分)
1、下面程序是整元换零钱问题。

把1元兑换成1角、2角和5角的零钱,打印所有的不同的换法。

#include <stdio.h>
void main()
{
int x,y,z,n;
____________ ;
for (x=0;x<=10;x++)
for (y=0;y<=5;y++)
for (z=0;z<=2;z++)
if ( _________________________ )
{
n++;
printf("换法%2d: 1角%2d张+2角%d张+5角%d张
\n",n,x,y,z);
}
}
2、以下函数利用插入排序方法对含有n个元素的数组x[]进行排序。

void insert(int x[],int n)
{
int i,j;
int temp;
for (i=1;i<n;i++)
{
temp=x[i];
j=i-1;
while (j>=0 && temp<x[j])
{
;
j--;
}
x[j+1]= ;
}
}
3、下面程序显示从3起小于100的所有双素数(双素数:如果p和q都是素数且q=p+2,则p/q称为双素数,例如3/5,5/7都是双素数)。

#include "stdio.h"
int prime(int m);
int main(int argc, char* argv[])
{
int p,q;
for (p=3;p<100;p+=2)
{
q = ;
if ( prime(p) && prime(q) ) printf("%d/%d\n",p,q);
}
return 0;
}
int prime(int m)
{
int i;
for ( i = 2; ; i++ )
if ( m % i == 0 ) ;
if ( i > m/2 ) return 1;
else return 0;
}
4、下面的函数strcat()实现将字符串str2连接到字符串str1的功能。

请在程序的空白处填入一条语句或一个表达式。

char *strcat(char *str1,char *str2)
{
char *t=str1;
while ( ) str1++;
while ( *str2 )
{
;
str1++;
str2++;
}
*str1= ;
return (t);
}
三、编程题(60分)
1、输入一个正整数n (1<n≤6),根据下式生成1个n*n的方阵,然后将该方阵转置(行列互换)后输出。

10分a[i][j] = i * n + j + 1(0≤i≤n-1,0≤j≤n-1)
例如n=3时:
1 2 3 1 4 7
A= 4 5 6 转置成B= 2 5 8
7 8 9 3 6 9
2、请设计函数double exp(double x),利用e x=1+x+x2/2!+x3/3!+x4/4!+…,计算e x的近似值,要求误差小于10-6。

20分
3、Fibonacci数列A={1,1,2,3,5,8,…}有如下性质:30分
a0=a1=1
a i=a i-1+a i-2 i>1
对于给定的n,另外有一个由n个元素组成的数列X={x0,x1,…,x n},该数列中各元素的值为:x i=a i/a i+1i=0,1,2,…,n,请将X中的元素按由小到大排序,排序用选择法或冒泡法,排序后的数列X输出到文本文件x.txt中,X中的各元素仍以分数形式表示。

例如,当n=5时,排序前的X={1/1,1/2,2/3,3/5,5/8},排序后的X={1/2,3/5,5/8,2/3,1/1}。

相关文档
最新文档