194道C语言复习练习题及答案
(完整版)C语言题库(带详解答案)

(完整版)C语⾔题库(带详解答案)⼀单项选择题1.(A)是构成C语⾔程序的基本单位。
A、函数B、过程C、⼦程序D、⼦例程2.C语⾔程序从 C开始执⾏。
A) 程序中第⼀条可执⾏语句 B) 程序中第⼀个函数C) 程序中的main函数 D) 包含⽂件中的第⼀个函数3、以下说法中正确的是(C)。
A、C语⾔程序总是从第⼀个定义的函数开始执⾏B、在C语⾔程序中,要调⽤的函数必须在main( )函数中定义C、C语⾔程序总是从main( )函数开始执⾏D、C语⾔程序中的main( )函数必须放在程序的开始部分4.下列关于C语⾔的说法错误的是(B)。
A) C程序的⼯作过程是编辑、编译、连接、运⾏B) C语⾔不区分⼤⼩写。
C) C程序的三种基本结构是顺序、选择、循环D) C程序从main函数开始执⾏5.下列正确的标识符是(C)。
A.-a1B.a[i]C.a2_iD.int t5~8题为相同类型题考点:标识符的命名规则(1)只能由字母、数字、下划线构成(2)数字不能作为标识符的开头(3)关键字不能作为标识符选项A中的“-” ,选项B中“[”与“]”不满⾜(1);选项D中的int为关键字,不满⾜(3)6.下列C语⾔⽤户标识符中合法的是( B)。
A)3ax B)x C)case D)-e2 E)union选项A中的标识符以数字开头不满⾜(2);选项C,E均为为关键字,不满⾜(3);选项D中的“-”不满⾜(1);7.下列四组选项中,正确的C语⾔标识符是(C)。
A) %x B) a+b C) a123 D) 123选项A中的“%” ,选项B中“+”不满⾜(1);选项D中的标识符以数字开头不满⾜(2)8、下列四组字符串中都可以⽤作C语⾔程序中的标识符的是(A)。
A、print _3d db8 aBcB、I\am one_half start$it 3paiC、str_1 Cpp pow whileD、Pxq My->book line# His.age选项B中的“\”,”$” ,选项D中“>”,”#”,”.”,”-”不满⾜(1);选项C中的while 为关键字,不满⾜(3)9.C语⾔中的简单数据类型包括(D)。
c语言基础试题库及答案

c语言基础试题库及答案一、选择题1. C语言中,用于定义一个结构体的关键字是:A. structB. unionC. enumD. typedef答案:A2. 下列哪个选项不是C语言的标准数据类型?A. intB. floatC. charD. string答案:D3. 在C语言中,用于实现循环的关键字是:A. whileB. forC. ifD. switch答案:A、B4. C语言中,用于定义函数的关键字是:A. functionB. defC. voidD. int答案:C5. 下列哪个选项是C语言中的合法变量名?A. 2variableB. variable2C. variable_2D. int答案:B、C二、填空题1. C语言中,________关键字用于定义一个数组。
答案:int2. 在C语言中,________关键字用于定义一个指针。
答案:*3. C语言中,________关键字用于定义一个函数。
答案:int4. 在C语言中,________运算符用于求两个数的和。
答案:+5. C语言中,________运算符用于判断两个数是否相等。
答案:==三、简答题1. 请简述C语言中函数的定义和调用过程。
答案:函数定义包括函数的返回类型、函数名、参数列表和函数体。
函数调用则是通过函数名和参数列表来调用已定义的函数。
2. 解释C语言中指针的概念及其用途。
答案:指针是一种变量,它存储了另一个变量的内存地址。
指针常用于动态内存分配、数组处理和函数参数传递。
四、编程题1. 编写一个C语言程序,计算并输出100以内所有偶数的和。
答案:```c#include <stdio.h>int main() {int sum = 0;for(int i = 1; i <= 100; i++) {if(i % 2 == 0) {sum += i;}}printf("Sum of even numbers from 1 to 100 is: %d", sum);return 0;}```2. 编写一个C语言函数,用于交换两个整数变量的值。
C语言全部章节习题集及答案

《C语言程序设计》1 C语言概述一、单项选择题第一章 C语言概述一、选择题:1、一个C程序的执行是从( A )。
A本程序的main函数开始,到main函数结束B本程序文件的第一个函数开始,到本程序文件的最后一个函数结束C本程序的main函数开始,到本程序文件的最后一个函数结束D本程序文件的第一个函数开始,到本程序main函数结束2、在 C 语言中,每个语句必须以( D )结束。
A. 回车符B. 冒号C. 逗号D. 分号3、C 语言规定:在一个源程序中,main函数的位置( C )。
A. 必须在最开始B. 必须在系统调用的库函数的后面C. 可以任意D. 必须在最后4、一个C 语言程序是由( B )。
A. 一个主程序和若干子程序组成B. 函数组成C. 若干过程组成D. 若干子程序组成5、下列说法中错误的是( D )。
A. 主函数可以分为两个部分:主函数说明部分和主函数体B. 主函数可以调用任何非主函数的其他函数C. 任何非主函数可以调用其他任何非主函数D. 程序可以从任何非主函数开始执行6、用 C 语言编写的源文件经过编译,若没有产生编译错误,则系统将( C )。
A. 生成可执行目标文件B. 生成目标文件C. 输出运行结果D. 自动保存源文件二、填空题:1、C 语言只有32个关键字和9种控制语句。
2、每个源程序有且只有一个 main 函数,系统总是从该函数开始执行C语言程序。
3、C 语言程序的注释可以出现在程序中的任何地方,它总是以 \* 符号作为开始标记,以 */ 符号作为结束标记。
4、C 语言中,输入操作是由库函数scanf完成的,输出操作是由库函数printf完成的。
5、系统默认的 C 语言源程序文件的扩展名是 .c,经过编译后生成的目标文件的扩展名是 .obj,经过连接后生成的可执行文件的扩展名是.exe 。
6、C 语言的标识符只能由字母、数字和下划线三种字符组成。
第三章数据类型、运算符和表达式一、选择题:1、以下选项中,不正确的 C 语言浮点型常量是( C )。
C语言全部题目及答案

C 语言全部题目及答案Exercise1:Programming Environment and Basic Input/Output1. Write a program that prints “This is my first program!” on the screen.(a) Save this program onto your own disk with the name of e2-1a;(b) Run this program without opening Turbo C;(c) Modify this program to print “This is my second program!”, then save it ase2-1b. Please do not overwrite the first program.2. Write a program that prints the number 1 to 4 on the same line. Write the programusing the following methods:(a) Using four “printf” statemen ts.(b) Using one “printf” statement with no conversion specifier (i.e. no ‘%’).(c) Using one “printf” statement with four conversion specifiers3 .(a) Write a program that calculates and displays the number of minutes in 15 days.(b) Write a program that calculates and displays how many hours 180 minutes equal to.(c) (Optional) How about 174 minutes?ANSWERS:#include<stdio.h>int main(){printf("1"); printf("2"); printf("3"); printf("4");return 0;}return 0; }#include<stdio.h>int main(){float days,minutes; days = 15; int main() {printf("This program!");return 0;int main(){float minutes,hours;printf("The numberminutes in 15 are %f\n", minutes);printf("This program!"); int main() {return 0; }#include<stdio.h> #include<stdio.h> #include<stdio.h>of days firstmyisExercise 2: Data Types and Arithmetic Operations1. You purchase a laptop computer for $889. The sales tax rate is 6 percent. Write and execute a C program that calculates and displays the total purchase price (net price + sales tax).2 .Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area. Use the value 3.14159 for “ ”.3 .Write a program that reads in two numbers: an account balance and an annual interest rate expressed as a percentage. Your program should then display the new balance after a year. There are no deposits or withdraws – just the interest payment. Your program should be able to reproduce the following sample run:Interest calculation program. Starting balance? 6000Annual interest rate percentage? 4.25}#include<stdio.h>int main() {printf("%d%d%d%d",1,2,3,4);return 0; }hours = minutes / 60; printf("180 minutes equal to %f hours\n", hours);return 0; }#include<stdio.h>int main() {float minutes,hours;#include<stdio.h>int main(){float net_price,sales_tax,total;net_price = 889;sales_tax = net_price * 0.06;total = net_price + sales_tax;printf("The total purchase price is %g", total);return 0;}#include<stdio.h>int main(){printf("Please input a number as radius:\n");float radius,diameter,circumference,area;scanf("%f",&radius);printf("The diameter is %g\n",diameter = radius * 2);printf("The circumference is %g\n",circumference = radius * 2 * 3.14159); printf("The area is %g\n", area = radius * radius * 3.14159);return 0;}#include<stdio.h>{float SB,percentage,NB;printf("Interest calculation program\n\nPlease enter the Starting Balance:"); scanf("%f",&SB);printf("Please enter the Annual interest rate percentage:");scanf("%f",&percentage);NB = SB * percentage / 100 + SB;printf("\nThe Balance after one year is:%g",NB);return 0;}Exercise 3: Selection structure1 . Write a C program that accepts a student’s numerical grade, converts thenumerical grade to Passed (grade is between 60-100), Failed (grade is between 0-59), or Error (grade is less than 0 or greater than 100). 2 . Write a program that asks the user to enter an integer number, then tells theuser whether it is an odd or even number. 3 . Write a program that reads in three integers and then determines and prints thelargest in the group.ANSWER: #include<stdio.h>#include<stdio.h>int main() {#include<stdio.h>int main() {int grade;printf("Please enter the grade:");scanf("%d",&grade);if (grade >= 60 && grade <= 100) printf("Passed."); else if (grade >= 0 && grade <60)#include<stdio.h>int main() {int a,b,c;printf("Please enter 3 integer numbers\n"); printf("Then I'll tell you which is thelargest\n"); scanf("%d%d%d",&a,&b,&c); if (a > b && a > c) printf("%d is the largest",a);else if (b > a && b > c) printf("%d is the largest",b); else if (c > a && c > b)int a;printf("Please enter an integer number\n");printf("Then I'll tell you whether it's an odd or even number");scanf("%d",&a);if (a%2 == 0)printf("%d is an even number",a);elseprintf("%d is a odd number",a);return 0;}Exercise 4: ‘switch’statement and simple “while” repetition statement1. Write a program that reads three integers an abbreviated date (for example: 26 12 94) andthat will print the date in full; for example: 26th December 1994. The day should be followed by an appropriate suffix, ‘st’,‘nd’,‘rd’ or ‘th’. Use at least one switch statement.2 .Write a C program that uses a while loop to calculate and print the sum of the even integersfrom 2 to 30.3. A large chemical company pays its sales staff on a commission basis. They receive £ 200 perweek plus 9% of their gross sales for that week. For example, someone who sells £ 5000 of chemicals in one week will earn £ 200 plus 9% of £5000, a total of £650. Develop a C program that will input each salesperson’s sales for the previous week, and print out their salary.Process one person’s figures at a time.Enter sales in pounds(-1to end):5000.00Salary is:650.00Enter sales in pounds(-1to end):00.00Salary is:200.00Enter sales in pounds(-1to end):1088.89Salary is:298.00Enter sales in pounds(-1to end):-1Optional:4. A mail order company sells five different products whose retail prices are shown in thefollowing table:Product Number1 2Retail Price (in pounds)2.984.503 4 59.98 4.49 6.87Write a C program that reads in a series of pairs of numbers as follows:(1). Product number(2). Quantity sold for one dayYour program should use a switch statement to help determine the retail price for each product, and should use a sentinel-controlled loop to calculate the total retail value of all products sold in a given week (7days).ANSWER:#include<stdio.h>int main(){printf("Please enter three numbers for date:");int day,month,year;scanf("%d %d %d",&day,&month,&year);if(day>31)printf("Error");else{switch (day){case 1:printf("1st");break;case 2:printf("2nd");break;case 3:printf("3rd");break;case 21:printf("21st"); break;case 22:printf("22nd"); break;case 23:printf("23rd"); break;case 31:printf("31st"); break;default:printf("%dth",day); }}switch(month){#include <stdio.h>int main(){int a,b;a=0;b=2;while (b<=30){a=a+b;b=b+2;}printf("The sum of the even integers from 2 to 30 is %d",a);return 0;}Exercise 5: ‘for’ and ‘do … while ” repetition statements1. Write a program which uses a do/while loop to print out the first 10 powers of 2 other than 0 (ie. it prints out the values of 21, 22, ..., 210). Use a for loop to do the same.2. The constant can be calculated by the infinite series:= 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 +....case 1: printf("January ");break;case 2: printf("February ");break;case 3: printf("March ");break;case 4: printf("April ");break;case 5: printf("May ");break;case 6: printf("June ");break;case 7: printf("July ");break;case 8: printf("August ");break;case 9: printf("September ");break;#include<stdio.h> int main() { float a,b;while (a>0 ) {printf("Enter sales in pounds (-1 to end):");scanf("%f",&a); b=200+a*0.09; if (a==-1) printf(" ");else printf("Salary is %.0f\n",b); }return 0;Write a C program that uses a do/while loop to calculate using the series. The program should ask the user how many terms in the series should be used. Thus ifthe user enters ‘3’, then the program should calcula te as being 4 - 4/3 + 4/5.Nested repetition3. Write a program that prints the following diamond shape. You may use printf statements that print either a single asterisk (*) or a single blank. Maximize your use of repetition (with nested for statements) and minimize the number of printf statements.*****************************************4. Write a program to print a table as follows:1*1= 1 2*1= 2 3*1= 3 ….9*1= 9ANSWER:#include<stdio.h> int main(){int a,b;a=0;b=1;do{a++;9*4=36 9*5=459*6=54#include <stdio.h>int main(){double c,pie,p;int a,b,d,n;printf("Enterterms:");scanf("%d",&a);printf("Pie=");9*7=63 9*8=729*9=81#include <stdio.h>int main(){int row,a,b,j;row=1;j=4;while(row<=5){for(a=j;a>=1;a=a-1) printf(" ");2*2= 43*2= 69*3=27 9*2=183*3= 9#include <stdio.h>int main () { int i, j;for (i=1; i<=9; i++) {for (j=1; j<=9; j++) if (i>=j)printf("%1d*%1d=%2d ", i, j, i*j); printf("\n"); }getchar(); return 0;int main() { int a;for(a=2;a<=1024;a=a *2) printf("%d",a); return 0; }p=p+pie;if(n>1&&n<=a) {if(n%2!=0) printf("+"); else printf("-"); }printf("4/%d",d); n++; }printf("\n=%f",p); return 0; }}row=1; j=1;while(row<=5){ for(a=1;a<=j;a=a +1) printf(" "); for(b=1;b<=9-2*j;b++) printf("*"); for(a=1;a<=j;a=a +1) printf(" "); printf("\n"); row++;Exercise 6: Simple Functions1. Write a C program that reads several numbers and uses the functionround_to_nearest to round each of these numbers to the nearest integer.Theprogram should print both the original number and the rounded number.2. Write a program that reads three pairs of numbers and adds the larger of the firstpair,the larger of the second pair and the larger of the third e a function to return the larger of each pair.3.A car park charges a£2.00minimum fee to park for up to3hours,and anadditional£0.50for each hour or part hour in excess of three hours.The maximum charge for any given24-hour period is£10.00.Assume that no car parks for more than24hours at a time.Write a C program that will calculate and print the parking charges for each of3 customers who parked their car in the car park yesterday.The program should accept as input the number of hours that each customer has parked,and output the results in a neat tabular form,along with the total receipts from the three customers:Charge2.002.50 10.0014.50The program should use the function calculate_charges to determine the charge for each customer.ANSWER: #include<stdio.h> int main() {float larger_Number(float,float); float num1,num2,total=0;int a=0;while (a<3) { void round_to_nearest(float); float num; while (5){ total=total+larger_Number(num1,num2);a=a+1; }#include<stdio.h> #include<math.h> int main() {printf("Please input a number:"); scanf("%f",&num);TOTAL Hours 29.524.0 Car 4.0 1.5 2 3 1#include <stdio.h> int main() {float calculate_charges(float);float hour1,hour2,hour3,charge1,charge2,charge3,total1=0,total2=0;printf("Please input three car's parking hours:"); scanf("%f%f%f",&hour1,&hour2,&hour3);charge1=calculate_charges(hour1); charge2=calculate_charges(hour2); charge3=calculate_charges(hour3);printf("Car Hours Charge\n"); printf("1%10.1f%10.2f\n",hour1,charge1); printf("2%10.1f%10.2f\n",hour2,charge2);void round_to_nearest(float num1) {int near_integer; intsmall_integer=floor(num1);if (num1-small_integer>=0.5) near_integer=ceil(num1); elsenear_integer=floor(num1);printf("\nThe nearest integer of the number is:%d\n",near_integer); }printf("\nThe total is %f",total);return 0; }float larger_Number(float num1,float num2) { float larger;if (num1>=num2) {printf("%f",num1); larger=num1; } else {printf("3%10.1f%10.2f\n",hour3,charge3);total1=hour1+hour2+hour3;total2=charge1+charge2+charge3;printf("TOTAL%7.2f%9.2f",total1,total2);return 0;}float calculate_charges(float hour){float charge;if (hour<=3)charge=2;if (hour>3 && hour<=19)charge=2.+0.50*(hour-3.);if (hour>19 && hour<=24)charge=10;return(charge);}Exercise 7: More Functions1.Write a program that uses sentinel-controlled repetition to take an integer as input,and passes it to a function even which uses the modulus operator to determine if the integer is even. The function even should return 1 if the integer is even, and0 if it is not.base exponentThe program should take the value returned by the function even and use it to print out a message announcing whether or not the integer was even.2.Write a C program that uses the function integerPower1(base,exponent)to return the value of:base exponentso that, for example, integerPower1(3, 4) gives the value 3 * 3 * 3 * 3.Assume that exponent is a positive, non-zero integer, and base is an integer.The function should use a for loop, and make no calls to any math library functions.3. Write a C program that uses the recursive function integerPower2(base,exponent) to return the value of:base exponentso that, for example, integerPower2(3, 4) gives the value 3 * 3 * 3 * 3. Assume that exponent is a positive, non-zero integer, and base is an integer.The function should make no calls to any math library functions.(Hint:the recursive step will use the relationship:base exponent=base.base exponent-1and the base case will be when exponent is1since:base1=base.)ANSWER:#include<stdio.h>int main(){int a,b;int judge(int);void judge1(int);printf("Please enter a number");scanf("%d",&a);while(a>=-1){b=judge(a);judge1(b);printf("Please evter a number");scanf("%d",&a);}return 0;}int judge(int x){if (x%2!=0)return (0);elsereturn (1);}void judge1(int x){if (x==1)printf("It's even\n"); elseprintf("It's odd\n");#include<stdio.h>int main(){int integerPower2(int,int);int base,exponent,result;printf("This program cancalculate the power\n");printf("Enter a integer basenumber:\n");scanf("%d",&base);printf("Enter a non-zerointeger number as the exponent:\n");scanf("%d",&exponent);result=integerPower2(base,expo nent);printf("The power is:%d",result); return 0;}int integerPower2(int x,int y){if(y==1)return (x);elsereturn (x*integerPower2(x,y-1)); }#include <stdio.h>int main(){int integerPower1(int,int);int base,exponent,answer;printf("Let us calculate the power\n");} printf("Please enter a integer base number:\n");scanf("%d",&base);printf("Please enter a non-zero integer number asthe exponent:\n");scanf("%d",&exponent);answer=integerPower1(base,exponent);printf("So the power is:%d",answer);return 0;}int integerPower1(int x,int y){int i,a;Exercise 08: Arrays1.Write a program that reads ten numbers supplied by the user into a singlesubscripted array,and then prints out the average of them.2. Write a program that reads ten numbers supplied by the user into a 2 by 5 array,and then prints out the maximum and minimum values held in:(a)each row(2rows)(b) the whole array3 .Use a single-subscripted array to solve the following problem. Read in 20numbers,each of which is between10and100,inclusive.As each number is read, print it only if it is not a duplicate of a number already read.Prepare for the “worst case”in which all 20 numbers are different. Use the smallest possible array to solve this problem.#include<stdio.h>int main(){#define MAXGRADES 10 int grades[MAXGRADES]; int i, total = 0;#include<stdio.h>int main(){#define MAXNUM 5int number[MAXNUM]; int i,j,a;ANSWER: #include<stdio.h> int main() {#define NUMROWS 2 #define NUMCOLS 5int number[NUMROWS][NUMCOLS]; int i,j,max1,max2,min1,min2;for (i=0;i<NUMROWS;i++){ printf("Please input 5 numbers with space between each other:\n"); for (j=0;j<NUMCOLS;j++) scanf("%d",&number[i][j]); }max1=number[0][0]; min1=number[0][0]; max2=number[1][0];{ printf("Enter a number:"); scanf("%d",&grades[i]); }printf("\nThe average of the numbers\n"); for(i=0;i<MAXGRADES;i++) { printf("%d",grades[i]); total+=grades[i]; }average = total/10.0;for(i=0;i<MAXNUM;i++) scanf("%d",&number[i]);a=0;for(i=0;i<MAXNUM;i++) { for(j=0;j<i;j++) {if(number[i]==number[j])a++;}min2=number[1][0];for(j=0;j<NUMCOLS;j++) { if(number[0][j]>=max1) max1=number[0][j];if(number[0][j]<=min1)min1=number[0][j];if(number[1][j]>=max2)max2=number[1][j];if(number[1][j]<=min2)min2=number[1][j];}printf("The max of the first row is %d\n",max1);printf("The min of the first row is %d\n",min1);printf("The max of the second row is %d\n",max2);printf("The min of the second row is %d\n",min2);printf("The max of two rows is ");if (max1>=max2)printf("%d\n",max1);else printf("%d\n",max2);printf("The min of two rows is ");if (min1<=min2)printf("%d\n",min1);else printf("%d\n",min2);return 0;}Exercise 9: More Arrays1. Write a program that enters 5 names of towns and their respective distance (aninteger) from London in miles. The program will print of the names of the towns that are less than 100 miles from London. Use arrays and character strings to implement your program.2. Write a program that prompts the user to type in four character strings, placesthese in an array of strings, and then prints out: (e.g. I am Peter Pan)(i) The four strings in reverse order. (e.g. Pan Peter am I)(ii) The four strings in the original order, but with each string backwards. (e.g. I ma reteP naP)(iii) The four strings in reverse order with each string backwards. (e.g. naP reteP ma I)#include<stdio.h>int main(){char character[5][20];int integer[5];int i;for(i=0;i<5;i++){ printf("Please enter a name of a town:\n");scanf("%s",character[i]);printf("Enter its distance from London in miles:\n");scanf("%d",&integer[i]);}printf("The towns that are less than 100 miles from London are:\n"); for(i=0;i<5;i++){if(integer[i]<100)printf("%s",character[i]);}return 0;}Exercise 10: Pointers1. Write a program that reads 5 integers into an array, and then uses four differentmethods of accessing the members of an array to print them out in reverse order.//Pan Peter am I #include<stdio.h> int main() {char four[4][81]; int i;printf("Please input four words:\n");for(i=0;i<4;i++) scanf("%s",four[i]);printf("The four strings in reverse order is :\n"); for(i=3;i>=0;i--) { printf("%s",four[i]);//naP reteP ma I #include <stdio.h> int main() {char four[4][81]; int i,j;printf("Please input four words:\n"); for(i=0;i<4;i++)scanf("%s",four[i]); printf("The four strings are:\n"); for(i=3;i>=0;i--) {for(j=0;four[i][j]!='\0';j++); for(j=j-1;j>=0;j--) {2. Write a program that reads 8 floats into an array and then prints out the second,fourth, sixth and eighth members of the array, and the sum of the first, third, fifth and seventh, using pointers to access the members of the array.3. (Optional) Write a program that use a SINGLE FUNCTION (用一个函数)tofind and return simultaneously both the lowest and highest values in an array of type int. Suppose the size of the array is 6.ANSWER:#include<stdio.h>int main(){int num1[5],i;printf("Please input 5 numbers:\n");for (i=0;i<5;i++)scanf("%d",&num1[i]);//the first wayprintf("\nPrint them out in reverse order in the first way:\n");for (i=4;i>=0;i--)printf("%d",num1[i]);//the second wayprintf("\nPrint them out in reverse order in the second way:\n");int *num2;num2 = &num1[0];for (i=4;i>=0;i--)printf("%d",*(num2+i));//the third wayprintf("\nPrint them out in reverse order in the third way:\n");for(i=4;i>=0;i--)printf("%d",*(num1+i));//the fourth wayprintf("\nPrint them out in reverse order in the fourth way:\n");int *num4;num4 = &num1[4];for (i=0;i<5;i++)printf("%d",*(num4-i));return 0;}#include<stdio.h>int main(){float num[8];int i;printf("Please input 8 floats:\n");for (i=0;i<8;i++)scanf("%f",&num[i]);//first, print out the second,fourth,sixth and eighthmembers of the arrayfor (i=1;i<8;i=i+2)printf("%f",*(num+i));//second, print out the sum of thefirst,third,fifthand seventhfloat total;for (i=0;i<8;i=i+2)total = total+*(num+i); #include<stdio.h>void SingleFunction(int *,int *); int main(){int num[6];int i;printf("Please input 6numbers:\n"); for (i=0;i<6;i++)scanf("%d",&num[i]);SingleFunction(num,num); return 0;}void SingleFunction(int *max,int *min) {int i,maxnum,minnum; maxnum = *max++;minnum = *min++;for(i=-1;i<5;i++)。
C语言全部考试系统题库含答案(可编辑修改word版)

目录
目录................................................................1 单元练习题一 C 语言基础知识 .........................................3
一、 判断题 ...................................................3 二、 单项选择题 ...............................................4 三、 读程序选择题 .............................................7 四、程序填空题 ..................................................8 五、编程题 .....................................................10 单元练习题二 C 语言程序结构 ........................................10 一、 判断题 ..................................................10 二、 单项选择题 ..............................................11 三、 读程序选择题 ............................................18 四、 程序填空题 ..............................................30 五、 编程题 ..................................................35 单元练习题三 数组..................................................36 一、 判断题 ..................................................36 二、 单项选择题 ..............................................37 三、读程序选择题 ...............................................39 四、程序填空题 .................................................43 五、编程题 .....................................................49 单元练习题四 函数..................................................49 一、 判断题 ..................................................49 二、 单项选择题 ..............................................50 三、读程序选择题 ...............................................52 四、程序填空题 .................................................60 五、编程题 .....................................................63 单元练习题五 预处理................................................63 一、 判断题 ..................................................63 二、 单项选择题 ..............................................64 三、读程序选择题 ...............................................64 四、程序填空题 .................................................65 五、编程题 .....................................................65 单元练习题六 指针..................................................66 一、 判断题 ..................................................66 二、 单项选择题 ..............................................66 三、读程序选择题 ...............................................67 四、程序填空题 .................................................74 五、编程题 .....................................................77 单元练习题七 结构体与共用体........................................78 一、 判断题 ..................................................78 二、 单项选择题 ..............................................78
c语言试题及答案

c语言试题及答案C语言试题及答案一、选择题1. 在C语言中,以下哪个是正确的数据类型?A. 整数型B. 浮点型C. 字符型D. 所有选项答案:D2. 以下哪个是C语言中的逻辑运算符?A. &&B. ||C. !D. 所有选项答案:D3. 在C语言中,哪个关键字用于定义一个函数?A. intB. voidC. functionD. return答案:A二、填空题1. 在C语言中,一个基本的程序结构由_____、_____、_____三个部分组成。
答案:预处理指令;函数定义;语句2. 一个C语言程序总是从_____函数开始执行。
答案:main3. 在C语言中,若要实现循环,可以使用_____、_____、_____等循环结构。
答案:for;while;do-while三、简答题1. 简述C语言中数组的定义和使用。
答案:在C语言中,数组是一种数据结构,用于存储具有相同数据类型的元素集合。
数组定义的一般形式为:类型名数组名[常量表达式],其中类型名是数组元素的数据类型,数组名是数组的标识符,常量表达式是数组中元素的数量。
数组的使用包括初始化、访问和修改元素等。
2. 解释C语言中的指针及其作用。
答案:指针是C语言中一种特殊的变量,它存储了另一个变量的内存地址。
指针的主要作用是直接访问和操作内存地址,从而可以更灵活地处理数据。
指针的使用包括指针的声明、指针的初始化、指针的运算等。
四、编程题1. 编写一个C语言程序,实现求两个整数的和。
```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入两个整数:");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("两个整数的和是:%d\n", sum); return 0;}```2. 编写一个C语言程序,实现字符串的反转。
C语言200道练习题及答案

一维数组
题目1
题目2
题目3
题目4
求一维数组中的最大值 和最小值。
将一维数组中的元素逆 序存放。
查找一维数组中指定的 元素,并返回其下标。
求一维数组中所有元素 的和。
二维数组
题目5
题目6
求二维数组中所有元素的最大值和最小值 。
将二维数组转置,即行列互换。
题目7
题目8
查找二维数组中指定的元素,并返回其位 置。
C语言200道练习题 及答案
汇报人:XX
目录
• 基础知识练习题 • 数组与字符串练习题 • 函数与模块化练习题 • 指针与内存管理练习题 • 数据结构与算法练习题 • 综合应用练习题
01
基础知识练习题
变量与数据类型
声明整型变量并赋值
int a = 10;
声明字符型变量并赋值
char c = 'A';
代码优化
通过减少不必要的计算、消 除冗余代码等方式对代码进 行优化。
并行计算与多线程
了解并行计算和多线程的基 本概念,探索在程序中应用 并行计算和多线程技术提高 性能的可能性。
THANKS
感谢观看
掌握如何使用malloc()、calloc() 等函数在堆区动态分配内存空间
。
动态内存释放函数
了解如何使用free()函数释放之前 分配的内存空间,以避免内存泄漏 。
内存分配失败处理
熟悉在动态内存分配过程中,如何 处理分配失败的情况,如检查返回 值是否为NULL等。
05
数据结构与算法练习题
结构体与联合体
01
掌握如何定义指向函数的指针变量,以及如何通过函数指针调
用函数。
c语言基础试题及答案

c语言基础试题及答案一、选择题1. C语言中,以下哪个关键字用于定义一个结构体?A. structB. unionC. enumD. typedef答案:A2. 在C语言中,以下哪个运算符用于取地址?A. *B. &C. %D. #答案:B3. 下列哪个选项是C语言中的合法整数常量?A. 0x12B. 0X12C. 0x1GD. 0x1g答案:A4. C语言中,以下哪个函数用于计算字符串的长度?A. strlen()B. strcpy()C. strcat()D. strcmp()答案:A5. 在C语言中,以下哪个关键字用于定义一个函数?A. functionB. defC. defineD. void答案:D二、填空题1. C语言中,用于定义一个变量的关键字是________。
答案:int2. C语言中,用于定义一个数组的语法是________。
答案:type arrayName[arraySize];3. C语言中,用于定义一个指针的语法是________。
答案:type *pointerName;4. C语言中,用于定义一个函数的语法是________。
答案:type functionName(parameters);5. C语言中,用于定义一个枚举的语法是________。
答案:enum enumName {elements};三、简答题1. 简述C语言中指针和数组的关系。
答案:在C语言中,指针和数组有密切的关系。
指针可以指向数组的元素,数组名可以作为指向数组首元素的指针。
通过指针可以访问和修改数组中的元素。
2. 描述C语言中函数的调用过程。
答案:在C语言中,函数调用过程包括:调用函数、传递参数、执行函数体、返回结果。
调用函数时,程序控制权转移到被调用函数,函数执行完毕后,返回到调用点继续执行。
四、编程题1. 编写一个C语言程序,实现计算两个整数的和。
答案:```c#include <stdio.h>int main() {int num1, num2, sum;printf("Enter two numbers: ");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("The sum is: %d\n", sum);return 0;}```2. 编写一个C语言程序,实现字符串的反转。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C语言程序设计复习参考练习题语言程序设计复习参考练习题程序设计复习参考练习题,在对应的字母处标记“√”请在答案A、B、C、D中选出一个正确的答案中选出一个正确的答案,1. 一个C程序的执行是从【】。
A) 本程序的main函数开始,到main函数结束B) 本程序文件的第一个函数开始,到本程序文件的最后一个函数结束C) 本程序的main函数开始,到到本程序文件的最后一个函数结束D) 到本程序文件的第一个函数开始,到本程序的main函数结束2. 一个C语言程序是由【】。
A) 一个主程序和若干子程序组成B) 函数组成C) 若干过程组成D) 若干子程序组成3. C语言规定,在一个源程序中,main函数的位置【】。
A)必须在最开始B)必须在系统调用的库函数的后面C)可以在任何位置D)必须在最后4. 在C语言中,数字0X26是一个【】进制数。
A) 二B) 八C) 十D) 十六5. 设说明为int a[3]={1,2}, *p=a; 则*p与*(p+2)的值分别是【】。
A) 1和0B) 0和1 C) 1和2 D) 2和06. 设说明为int a=10; 执行语句a*=1+2+3; 后a的值是【】。
A) 15 B) 24 C) 33 D) 607. 为表示关系x≥y≥z,应使用C语言表达式【】。
A) (x>=y>=z) B) (x>=y)AND(y>=z) C) (x>=y)&&(y>=z) D) (x>=y)&(y>=z)8. 说明语句:int a[][3]={1,2,3,4,5,6,7,8,9}; 则a数组的行数为【】。
A) 不确定B) 1 C) 2 D) 39. 以下程序时,从键盘输入25,13,10<回车>,则输出结果是【】。
main() {int a1, a2, a3;scanf("%d,%d,%d", &a1, &a2, &a3);printf("a1+a2+a3=%d\n", a1+a2+a3);}A) a1+a2+a3=48 B) a1+a2+a3=25 C) a1+a2+a3=10 D) 不确定10. putchar函数可以向终端输出一个【】。
A) 整型变量值B) 实型变量值C) 字符串D) 字符或字符变量11. 执行下面程序,屏幕输出的值是【】int x;printf("%d\n", (x=3*5, x+5));A) 10 B) 15 C) 20 D) 512. 判断字符类型变量c是否为大写字母的正确表达式是【】。
A) 'A'<=c<='Z' B) (c>='A') & (c<='Z')C) (c>='A') && (c<='Z') D) ('A'<=c) AND ('Z'>=c)13. C语言规定:简单变量做实参时,它和对应形参之间的数据传递方式是【 】。
A) 地址传递B) 单向值传递C) 由实参传给形参,再由形参传回给实参D) 由用户指定传递方式14. 下面程序段的运行结果是【】。
char *s="abcde";s+=1;printf("%s\n", s);A) bcde B) abcde C) ab D) b15. 若有定义:int a[2][3]; 则以下对a数组元素的正确引用是【】。
A) *(a+1) B) *(a[1]+2) C) &a[0][0] D) a[1]+316. 若有定义:int s[4][6], t[6][4], (*p)[6]; 则以下正确的赋值语句是【】。
A) p=t; B) p=s[2]; C) p=s; D) p=t[3];17. 若有以下定义,则数组b占用内存的字节数是【】。
char b[]="C language";A) 14 B) 15 C) 8 D) 1118. 设说明为char str[6]={'a', 'b', '\0', 'c', 'd', '\0'}; 执行printf("%s", str); 后输出的结果是【】。
A) abcd B) abc C) ab D) ad19. 定义如下变量和数组,则语句for (i=0; i<3; i++) printf("%d ", x[i][2-i]); 的输出结果是【】。
int i;int x[3][3]={1, 2, 3, 4, 5, 6, 7, 8, 9};A) 1 5 9 B) 1 4 7 C) 3 5 7 D) 3 6 920. 有如下程序,运行后的输出结果是【】。
main() {int a=10, b=4, c=3;if(a<b) a=b;if(a<c) a=c;printf("%d,%d,%d\n", a, b, c);}A) 3,4,10 B) 4,4,3 C) 3,4,3 D) 10,4,321. 在C语言中,合法的字符常量是【】。
A) '\084' B) '\x43' C) 'ab' D) "\0"22. 若有定义和语句,则输出结果是【】。
int **pp, *p, a=10, b=20;pp=&p; p=&a; p=&b; printf("%d\n", *p, **pp);A) 10,20 B) 10,10 C) 20,10 D)20,2023. 若有以下定义和语句,则输出结果是【】。
char c1='b', c2='e';printf("%d,%c\n", c2-c1, c2-'a'+'A');A) 2,M B) 3,E C) 2,ED) 输出项与对应的格式控制不一致,输出结果不确定24. 在以下一组运算符中,优先级最高的运算符是【】。
A) <= B) = C) % D) &&25. 表达式(a=2,3), a+1 的值是【】。
A) 0 B) 2 C) 3 D) 426. 若执行printf("%d\n", strlen("a\n\"\x41")); 语句,其输出结果是【】。
A) 8 B) 7 C) 6 D) 427. 在循环语句的循环体中执行break语句,其作用是【】。
A) 跳出该循环体,提前结束循环B) 继续执行break语句之后的循环体各语句C) 结束本次循环,进行下次循环D) 终止程序运行28. 执行语句for(i=10; i>0; i--); 后,变量i的值为【】。
A) 10 B) 9 C) 0 D) 129. 如果定义一个整型变量int a; 使该变量字节不变,而正数值的表示范围扩大一倍的方式用【】。
A) signed B) long C) unsigned D) float30. 表达式10!=9的值是【】。
A) true B) 非零值C) 1 D) 031. 若int x=10; 则表达式x+(char)1/2.0 值的类型是【】。
A) int B) double C) float D) unsigned32. 以下不属于C语言关键字的是【】。
A) case B) byte C) do D) float33. C语言中,以下【】不是正确的常量。
A) 543210L B) 05078 C) -0x41 D) 1234534. 以下四组中都能正确作为C语言程序标识符的是【】组。
A) printf B) sort_1 C) pow D) book->namerow string_to_float string book.priceif PI 1_abc A#B35. 使下列程序段输出“123, 456, 78”,由键盘输入数据,正确的输入是【】。
int i, j, k;scanf("%d,%3d%d", &i, &j, &k);printf("%d,%d,%d\n", i, j, k);A) 12345678 B) 123, 456, 78 C) 123, 45678 D) 123, *4567836. 判断char类型的变量c1是否为数字字符的正确表达式为【】。
A) (c1>=0)&&(c1<=9) B) (c1>='0')&&(c1<='9')C) '0'<=c1<='9' D) (c1>='0')||(c1<='9')37. 若有语句int a=1,b=2,c=3; 则以下值为0的表达式是【】。
A) 'a'&&'b' B) a<=b C) (a>b)||(b<c) D) (!(a+b)==c&&a)38. C语言中的实数可以用多种形式表示,以下四种表示中,只有【】是错误的。
A) 23e+6 B) 13e-4 C) 0.3e1.2 D) .123439. 下面四个选项中,均是不合法的转义字符的选项是【】。
A) '\"' B) '\1011' C) '\011' D) '\abc''\\' '\' '\f' '\101''\xf' '\a' '\}' 'xlf'40. 以下符合C语言语法的赋值表达式是【】。
A) d=9+e=d+9 B) d=9+e, f=d+9 C) d=9+e, e++, d+9 D) d=9+e++=d+741. 若已定义:float aa=1234.5678; 则执行printf("%6.2f%d/n", aa, (int)(aa)); 则输出是【】。