c复习题目
C程复习资料

补充习题解答1:1.C 语言程序中可以对程序进行注释,注释部分必须用符号_____括起来。
A、‘{‘和’}’B、‘[‘和’]’C、“/*”和”*/”D、“*/”和”/*”答案:C,这题大家基本都没问题。
2.下列运算符中,优先级最低的是_____。
A、*B、!=C、+D、=答案:D。
本题考察的是运算符的优先级问题,顺序为:初等运算符>单目运算符>算术运算符>关系运算符>逻辑运算符>条件运算符>赋值运算符>逗号运算符.请大家记住这个顺序。
另外,大家在写程序的时候并不能够准确地确定优先级的时候,多加几对括号就可以了,因为在这种情况下读你程序的人可能也不确定优先级。
3.下列运算符中,优先级最低的是:_____A、*B、+C、==D、=答案:D,理由同上。
4.已知字符‘a’的ASCII码为97 ,执行下列语句的输出是_____。
printf ("%d, %c", ’b’, ’b’+1 ) ;A、98, bB、语句不合法C、98, 99D、98, c答案:D。
每一个字符都对应一个整型数值的ASCII码,故可以将字符以int型输出,反过来,也可以将符合ASCII码的int型数值进行字符。
关键在于输出格式控制。
5.有程序段如下:Int k=10;While(k=0)K=k-1;以下选项中描述正确的是_____。
A. 语句“k=k-1;”被执行10次。
B. 语句“k=k-1;”被执行1次。
C. 语句“k=k-1;”被执行无限多次。
D. 语句“k=k-1;”一次也不执行。
答案:D。
while循环体执行的条件为:while判断条件为真(非0为真0为假,特别注意,负数也为真)。
而本题的判断条件为k=0这个表达式的值,为0,故原题等价于while(0)。
所以在写程序的时候要特别避免类似的逻辑错误。
这两题很多同学有错。
6.写出判断一个年份为闰年的C语言表达式:______________________。
C语言全部题目及答案

C语言全部题目及答案Exercise 1: 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 itas e2-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” stateme nts.(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("This is my first program!");return 0;}#include<stdio.h>int main(){printf("This is my second program!"); return 0;} #include<stdio.h>int main(){printf("1");printf("2");printf("3");printf("4");return 0;}#include<stdio.h>int main(){printf("1234");return 0;}#include<stdio.h>int main(){printf("%d%d%d%d",1,2,3,4);return 0;}#include<stdio.h>int main(){float days,minutes;days = 15;minutes = days * 24 *60;printf("The numberof minutes in 15 daysare %f\n", minutes);return 0;}#include<stdio.h>int main(){floatminutes,hours;minutes = 180;hours = minutes / 60;printf("180 minutesequal to %fhours\n", hours);return 0;}#include<stdio.h>int main(){floatminutes,hours;minutes = 174;hours = minutes / 60;printf("174 minutesequal to %fhours\n", hours);return 0;}Exercise 2: Data Types and Arithmetic Operations1. You purchase a laptop computer for $889. The sales tax rate is 6 percent. Writeand 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.25Balance after one year: 6255ANSWER:#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>int main(){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 the numerical 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 the user whether it is an odd or even number.3.Write a program that reads in three integers and then determines and prints the largest in the group.ANSWER:#include<stdio.h> #include<stdio.h>int mai n() { int a; pri ntf ("P lea se ent er an int ege r num ber\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) and that 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 integers from 2 to 30. 3. A large chemical company pays its sales staff on a commission basis. They receive £200 per week plus 9% of their gross sales for that week. For example, someone#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)printf("Failed."); elseprintf("Error."); return 0; }#include<stdio.h> int main() {int a,b,c; printf("Please enter 3 integer numbers\n");printf("Then I'll tell you which is the largest\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)printf("%d is the largest",c); elseprintf("They're equal"); return 0; }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 salesfor the previous week, and print out t heir salary. Process one person’s figures at a time.Enter sales in pounds (-1 to end): 5000.00Salary is: 650.00Enter sales in pounds (-1 to end): 00.00Salary is: 200.00Enter sales in pounds (-1 to end): 1088.89Salary is: 298.00Enter sales in pounds (-1 to end): -1Optional:4. A mail order company sells five different products whose retail prices are shownin the following table:Product Number Retail Price (in pounds)1 2.982 4.503 9.984 4.495 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 pricefor 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; #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;}#include<stdio.h>int main()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){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;case 10: printf("October ");break;case 11: printf("November ");break;case 12: printf("December ");break;}printf("19%d",year);return 0;} {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;}Exercise 5: ‘for’ and ‘do … while” repetition statements1. Write a program which uses a do/while loop to print out the first 10 powersof 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 +....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 if the user enters ‘3’, then the program should calculate ? 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= 12*1= 2 2*2= 43*1= 3 3*2= 6 3*3= 9….9*1= 9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 ANSWER:#include<stdio.h> int main(){int a,b;a=0;b=1;do{a++;b=b*2;printf("%d",b); }while (a<=9);return 0;}#include<stdio.h> int main(){int a;for(a=2;a<=1024;a=a *2)printf("%d",a); return 0;} #include <stdio.h>int main(){double c,pie,p;int a,b,d,n;printf("Enterterms:");scanf("%d",&a);printf("Pie=");n=1;p=0;while(n<=a){if(n%2==0)b=-1;elseb=1;pie=(4.0*b)/(2.0*n-1.0);d=2*n-1;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;}#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(" ");for(b=1;b<=9-2*j;b++)printf("*");for(a=j;a>=1;a=a-1)printf(" ");printf("\n");row++;j--;}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++;j++;}return 0;}#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;}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 thefirst pair, the larger of the second pair and the larger of the third pair.Use a function to return the larger of each pair.3. A car park charges a £2.00 minimum fee to park for up to 3 hours, and anadditional £0.50 for each hour or part hour in excess of three hours. The maximum charge for any given 24-hour period is £10.00. Assume that no car parks for more than 24 hours at a time.Write a C program that will calculate and print the parking charges for each of 3 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:Car Hours Charge1 1.5 2.002 4.0 2.503 24.0 10.00TOTAL 29.5 14.50The program should use the function calculate_charges to determine thecharge for each customer.ANSWER:#include<stdio.h> #include<math.h> int main() { void round_to_nearest(float); float num; while (5) { printf("Please input a number:"); scanf("%f",&num); round_to_nearest(num); } return 0; } void round_to_nearest(float num1) { int near_integer; int small_integer=floor(num1); if (num1-small_integer>=0.5) near_integer=ceil(num1); else near_integer=floor(num1); printf("\nThe nearest integer of the number is:%d\n",near_integer); } #include<stdio.h> int main() { float larger_Number(float,float); float num1,num2,total=0; int a=0; while (a<3) {printf("Please input two numbers:"); scanf("%f%f",&num1,&num2); total=total+larger_Number(num1,num2); a=a+1; } 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("%f",num2); larger=num2; }printf("\n"); return (larger); }#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);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 integeras 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, and 0 if it is not.The 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:exponentbaseso 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 aninteger. 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:baseexponentso 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 aninteger. The function should make no calls to any math library functions.(Hint: the recursive step will use the relationship:base exponent= base . baseexponent - 1and the base case will be when exponent is 1 since : base 1= 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){ #include<stdio.h>int main(){int integerPower2(int,int);int base,exponent,result;printf("This program can calculate the power\n");printf("Enter a integer base number:\n"); scanf("%d",&base);printf("Enter a non-zero integer number as the exponent:\n");scanf("%d",&exponent);result=integerPower2(base,exponent);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;if (x==1)printf("It's even\n"); elseprintf("It's odd\n"); } 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 as the 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;a=1;for(i=1;i<=y;i++)a=x*a;return (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 (2 rows)(b) the whole array3.Use a single-subscripted array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, 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 10int grades[MAXGRADES];int i, total = 0;float average;for (i=0;i<MAXGRADES;i++){ printf("Enter a number:");scanf("%d",&grades[i]);}printf("\nThe average of the numbers\n"); #include<stdio.h>int main(){#define MAXNUM 5int number[MAXNUM];int i,j,a;printf("Please enter 5 numbers between 10 and 100\n");for (i=0;i<MAXNUM;i++)scanf("%d",&number[i]);a=0;for(i=0;i<MAXNUM;i++){ for(j=0;j<i;j++)for (i=0;i<MAXGRADES;i++) { printf("%d",grades[i]); total+=grades[i];}average = total/10.0;printf("is %f\n",average); return 0;} { if(number[i]==number[j]) a++;}if(a==0)printf("%d",number[i]);a=0;}return 0;}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];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;}//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]); //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++)printf("The four strings in reverse order is :\n");for(i=3;i>=0;i--){ printf("%s",four[i]);}return 0;} 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--){printf("%c",four[i][j]);} printf(" ");}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.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 (用一个函数)to findand 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 eighth members of the arrayfor (i=1;i<8;i=i+2)printf("%f",*(num+i));//second, print out the sum of the first,third,fifth and seventhfloat total;for (i=0;i<8;i=i+2)total = total+*(num+i);printf("\nthe total of four numbers are %f",total);return 0;} #include<stdio.h>void SingleFunction(int *,int *);int main() {int num[6];int i;printf("Please input 6 numbers:\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++){ if(maxnum < *(max+i))maxnum = *(max+i);}printf("The max is: %d\n",maxnum);for(i=0;i<6;i++){ if(minnum > *(min+i))minnum = *(min+i);}printf("The min is: %d",minnum);}。
c语言复习题面试题考试题-全

c语言复习题面试题考试题-全不定项选择题(针对以下题目,请选择最符合题目要求的答案,每道题有一项或二项正确答案。
针对每一道题目,所有答案都选对,则该题得分,所选答案错误或不能选出所有答案,则该题不得分。
题量为50道,每题2分,总分为100分。
)第一章1)对于C语言的描述说法错误的是()。
A、它是一种计算机程序设计语言B、它既有高级语言的特点,又具有汇编语言的特点C、它不可以作为系统设计语言,编写系统应用程序D、它可以作为应用程序设计语言,编写不依赖计算机硬件的应用程度2)在C语言中,下图所示的流程图符号代表的是()。
(选择一项)A、程序开始或结束B、判断和分支C、输入/输出指令D、计算步骤3、下列关于算法的说法正确的是()(选择二项)A、算法必须在有限步骤内解决问题B、算法可能需要无穷步才能解决问题C、算法应该有确定的结果D、算法的计算结果无法预知4、在C中,多行注释使用()符号结尾(选择一项)A、/某B、某/C、某D、ocB、.t某tC、.pptD、.c或.cpp7、以下对C语言源程序的结构特点描述错误的是()(选择一项)A、一个C语言源程序可以由一个或多个源文件组成B、每一个源文件只能有一个函数组成C、一个源程序有且只有一个main函数充当主函数D、每一个说明,每一个语句都必须以分号结尾8、下列对C语言头文件描述错误的是()(选择一项)A、中包含了标准的输入输出函数以及字符串出来函数B、中包含了数学运算函数C、中包含了各类基本函数D、中包含了时间和日期的处理函数9、从开发C语言程序到让计算机可以执行命令,需要经过以下步骤中正确的是()(选择一项)A、编辑编译预处理连接加载执行B、编辑预处理编译连接加载执行C、编辑预处理连接编译加载执行D、编辑预处理连接编译加载执行10、在C语言中,下图所示的流程图符号代表的是()。
(选择一项)A、程序开始或结束B、判断和分支C、输入/输出指令D、处理过程11、在C语言中,下图所示的流程图符号代表的是()。
c语言复习题(49题)

以下作业编程练习,每个主题至少选择4道题作为作业题(各主题中所列题目不足4题的按实际数量选做)。
每次作业计2分,作为平时成绩。
另外,此练习题作为C 语言上机考试的考题来源之一(共49题)。
一、 顺序结构程序设计========================================1 已知三角形的三边长为a ,b ,c ,计算三角形面积的公式为: area = ))()((c s b s a s s ---,s =)(21c b a ++ 要求编写程序,从键盘输入a ,b ,c 的值,计算并输出三角形的面积。
2 编程从键盘输入圆的半径r ,计算并输出圆的周长和面积。
二、 选择结构程序设计==========================================1 从键盘任意输入一个年号,判断它是否是闰年。
若是闰年,输出“Yes ”,否则输出“No ”。
已知符合下列条件之一者是闰年:能被4整除,但不能被100整除。
能被400整除。
2 通过键盘输入一个字符,判断该字符是数字字符、大写字母、小写字母、空格还是其他字符。
3 华氏和摄氏温度的转换公式为C =5/9×(F -32)。
其中,C 表示摄氏温度,F 表示华氏温度。
要求:华氏0℉~300℉,每隔20℉输出一个华氏温度对应的摄氏温度值。
4 编程判断输入整数的正负性和奇偶性。
5 编程计算分段函数e 1exx y -⎧⎪=⎨⎪-⎩ 000x x x >=< 输入x ,打印出y 值。
流程图如图1-2所示。
6 输入三角形的三条边a ,b ,c ,判断它们能否构成三角形。
若能构成三角形,指出是何种三角形(等腰三角形、直角三角形、一般三角形)。
7 在屏幕上显示一张如下所示的时间表:*****Time*****1 morning2 afternoon3 nightPlease enter your choice:操作人员根据提示进行选择,程序根据输入的时间序号显示相应的问候信息,选择1时显示"Good morning", 选择2时显示"Good afternoon", 选择3时显示"Good night",对于其他选择显示"Selection error!",用switch 语句编程实现。
C语言理论复习题

序号
题目
正 确 A B 答 案
51 52 53 54 55 56 57 58 59 60 61
使用strlen函数可以求出一个字符串的实际长度 对错 B (包含‘\0’字符)。 如有定义char a[]="student";则数组a的长度为7 对错 B 如有定义char a[20];则可以通过a=“I am a 对错 B boy”;给a赋值。 如有定义int a[2][3];则数组a的最后一个元素为 对错 A a[1][2]。 如有定义int a[3][4]={0}; 则数组a的所有元 对错 A 素初值均为0 C语言中数组名实质上是数组的首地址,是一个变 对错 B 量地址,可对其进行赋值 对错 B 构成数组的各个元素可以有不同的数据类型。 若有说明:int a[10];,则可以用a[10]引用数组a 对错 B 的第10个元素。 函数的形参为一个数组,则调用此函数时将数组名 对错 A 作为对应的实参。 do...while的循环体可能一次也不会执行。 对错 B
char *p[10];定义了一个指向字符数组的指针 对错 B 变量。 数组名实际上是此数组的首地址,所以数组名相当 62 对错 B 于一个指针变量。 do...while语句与while语句的区别仅仅是关键字 63 对错 B while的位置不同。 64 使用文件前必须先打开文件 对错 A
判断题 第 4 页
判断题
第 8 页
判断题
第 9 页
判断题
第 10 页
判断题
第 11 页
判断题
第 12 页
判断题
第 13 页
判断题
第 14 页
判断题
第 15 页
判断题
第 16 页
c语言程序设计复习题库

复习题库题号题 目 1. 某铁桶厂应客户要求定做一批铁桶,客户给出了铁桶的规格,高30cm ,半径10cm ,共订做1500个铁桶。
计算出所需的原材料。
2.利用系统库函数实现数学运算,求x y 。
3.从键盘上输入一个小写字母,把它转变为大写字母再输出。
4. 设圆半径r=1.5,圆柱高h=3,求圆柱体积,圆柱底面积,圆柱表面积。
用scanf ()输入数据,输出计算结果。
输出时要有说明,结果取小数点后两位数字。
5.由键盘输入n 的值,编程计算并输出n!的值。
6. 让用户输入一个年份,判断改年份是否是闰年– 被4整除不能被100整除,或者被400整除7. 有一个函数⎪⎩⎪⎨⎧--=11312x x x y ())10()101(1≥<≤<x x x写程序,输入x 的值,输出y 相应的值。
8. 在学生成绩管理中,经常要将成绩的百分制转换成对应的等级制。
90分以上为A 等,80-89为B 等,70-79为C 等,60-69分为D 等,其余为E 等。
编写程序,根据输入的百分制成绩,输出对应的等级。
9. 计算从出生年份(例如1996)到当前年份(例如2014)共经过了多少闰年,输出所有的闰年年份。
10. 从1开始做自然数的累加,当其累加和超过1000的时候,共计累加了多少数?当时的累加和是多少?11.百钱买百鸡问题 12. 计算出自然数SIX 和NINE 满足条件SIX+SIX+SIX=NINE+NINE 的个数CNT,以及所有满足此条件的SIX 与NINE 。
13.求 3—100之间的全部素数14. 图形编程图形编程15. 某歌手大赛,共有10个评委打分,分数采用百分制,去掉一个最高分,去掉一个最低分,然后取平均分,得到歌手的成绩,编程实现。
16.让用户输入10个整数,对10个整数进行降序排列 17.对用户输入的10个整数逆序排列并输出 18. 输出Fibonacci 序列前20项** * ** * * * ** * * * * * ** * * * * * * * ** * * * * * * * * * *19.在一个字符数组中查找一个指定的字符,若数组中含有该字符,则输出该字符在数组中第一次出现的位置,否则输出-1.20.写一个函数,求sn=a+aa+aaa+aaaa+aaaaa.....的值,a的值n的值均由用户指定。
C语言程序设计期末考试复习题及答案(答案与题目分离)

C语言考试期末考试复习题及答案一、选择题(1)一个C语言程序总是从()开始执行A)书写顺序的第一个函数B)书写顺序的第一条执行语句C)主函数main( )D)不确定(2)设int x=3,y=4,z=5,则下列表达式中的值为0的是()A) ‘x'&&’y’B)x||y+z&&y—z C) x〈=y D)!((x〈y)&&!z||1)(3)执行以下程序段后,i的值是()int i=10;switch(i+1){case 10:i++; break;case 11:++i;case 12:++i;break;default :i=i+1;}A) 11 B)13 C) 12 D) 14(4)语句while(!e);中的条件!e等价于()A)e==0 B)e!=1 C) e!=0 D)运行时出错(5)用int a[4]={1,2}; 对数组进行初始化后,数组元素a[3]的值是()A)随机值B) 0 C) 1 D)F(6)在执行char str[10]=“china\0”;strlen(str)的结果是()A)5 B) 6 D) 7 D 9(7)若有定义,char *p=”computer";则语句printf(“%c”,*(p+2))运行结果是()A) 随机值B) m C)o D)omputer(8)在以下函数调用语句中fun1(x,10,(x,10),fun2(y,10,(y,10)));函数fun1参数的个数为()A) 8 B) 4C)5 D)编译出错(9)在说明一个结构体变量时系统分配给它的存储空间是()A)该结构体中第一个成员变量所需存储空间B)该结构体中最后一个成员变量所需存储空间C)该结构体中占用最大存储空间的成员变量所需存储空间D) 该结构体中所有成员变量所需存储空间的总和Key:CDCAB ABBD1。
用C语言编写的代码程序A)可立即执行B)是一个源程序C)经过编译即可执行D)经过编译解释才能执行2。
C语言所有题目以及答案

C语言所有题目以及答案一.判断题1.关系运算符<=和==具有相同的优先级。
氮气。
7&3+12的值为15 n3.在turboc中,整型数据在内存中占2个字节。
y4.C语言本身不提供输入输出语句,输入输出操作由函数实现。
y5。
Char[]=“verygood”:为字符串数组赋值是一种合法声明。
y6。
定义宏时,宏名称必须用大写字母表示。
n7。
如果inti=10,则j=2;然后执行I*=j+8;最后一个I的值是28n8。
语句scanf(“%7.2f”和&A);是一种合法的扫描功能。
n9。
C语言中%运算符的操作数必须是整数。
Y10.字符处理函数strcpy(str1,str2)的功能是把字符串1接到字符串2的后面。
n11.a=(b=4)+(c=6)是一个合法的赋值表达式。
y12.整数-32100可分配给int和Longint变量。
y13。
报表printf(“%F%%”,1.0/3);输出为0.333N14.若有宏定义:#defines(a,b)t=a;a=b;b=t由于变量t没有定义,所以此宏定义是错误的。
n15.x*=y+8等价于x=x*(y+8)y16.如果inti=10,则j=0;如果(J=0)I++,则执行该语句;我--;I的值是11 n17。
C语言只能逐个引用数组元素,而不能一次引用整个数组。
y18。
如果a=3、B=2、C=1,则关系表达式“(a>B)==C”的值为“真”。
y19。
C语言的所有函数都是外部函数。
Y20.如果想使一个数组中全部元素的值为0,可以写成inta[10]{0*10};n21.定义和声明(如有):inta;查克;漂浮物;scanf(“%d、%c、%f”、&a、&c、&f);如果你通过键盘输入:10,a,12.5,那么a=10,C=a',f=12.5y22.如果有一个字符串,其中第十个字符为‘\\n’,则此字符串的有效字符为9个。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C复习资料1)能正确表示“当x 的取值在 [5,10]和[150,200]范围内为真,否则为假”的表达式是( )A. (x>=5)||(x<=10)&&(x>=150)||(x<=200)B. (x>=5)&&(x<=10)||(x>=150)&&(x<=200)C. (x>=5)||(x<=10)||(x>=150)||(x<=200)D. (x>=5)&&(x<=10)&&(x>=150)&&(x<=200)2)int a;if(a) printf(“%d”,a); 表示的是()A. a非零,输出a C. a>0,输出aB. a==0,输出a D a<0,输出a 3)逻辑运算符两侧运算对象的数据类型( )A.只能是 0 或 1B. 只能是 0 或非0整数C.可以是任何类型的数据D.只能是整数或字符型4)下面程序段运行的结果是( )char c1,c2;c1=’D’;c2=c1+32+3;printf(“%c,%c\n”,c1,c2);A) d,F B) D,FC) D,f D) d,f5)下面程序段输出结果是( )int x,y,z;x=5;y=6,z=7;if(x>y)x=y; y=z;z=x;printf(“x=%d,y=%d,z=%d\n”,x,y,z);A) x=5,y=6,z=5 B) x=5,y=7,z=5C) x=6,y=7,z=5 D) x=6,y=7,z=61、以下不能正确进行赋初值的语句是()A)char str[8]=”welcome!”; B) char str[]=”welcome!”;C)char str[20]=”welcome!”;D)char str[8]={‘w’,’e’,’l’,’c’,’o’,’m’,’e’,’!’};2、若有定义:int b[10]={4,2,9};则以下表达式中数组元素b[7]的值是()A) 9 B) 2 C) 4 D) 03、struct student{ int m1; char m2[2]; float m3;}aa;则m1的表示方法是()A) m1 B) struct.m1 C) aa->m1 D)aa.m14、以下非法的赋值语句是()A)m=(i=2,++i); B) k++;C) ++(s+1); D) b=j>0;5、设有定义:long int x= -1256789;则以下能够正确输出变量x值的语句是()A) printf(“x=%d\n”,x); B)printf(“x=%ld\n”,x);C) printf(“x=%8d\n”,x); D) printf(“x=%s\n”,x);6、以下选项中与k=++n完全等价的表达式是()A) k=n,n=n+1 B) n=n+1,k=nC) k=n++ D) k+=n+17、在定义自定义函数时,函数值的类型为int,此时return语句后面表达式的值的类型是()A) void B) int C) float D) double9、Struct ma{ char c[2];int d;};struct sk{ int a; float b;Struct ma ya;}myb;要为d变量赋值,如何表示myb.ya.d10、从键盘输入一个字符型变量c,则正确的输入语句是()A) scanf(“%d”,c); B) scanf(“%3c”,&c);C) scanf(“%c”, c); D) scanf(“%s”, c);11、将算术表达式12.3*(6+sin450)/22表示成C表达式,正确的a.12.3*(6+sin45)/22b.12.3*(6+sin450)/22c.12.3*(6+sin45*3.1415/180)/22d. 12.3*(6+sin(45*3.1415/180))/2212、表达式5>3&&2>3||0<2的结果是a. 1b. 0c. falsed. true13、如果有如下函数定义语句:int MyFunction(int a,int b),则错误的是a. int x=MyFunction(5,7)b. MyFunction(5,7)c.int x=MyFunction(5,7)+xd. int x= MyFunction(‘5’,’7’)14、以下语句中有语法错误的是a. for(int I=0;I<10;I++) ┅┅;b. while(n!=0)++n;c. if(a>0) a--;d. break l11;15、以下对一维数组赋初值,正确的是a.char a[50]=”this is a string”;b.c har a[]=”this is a string”;c. int a[2]={0,1,2}d. a[]={‘0’,’1’,’2’,’3’}写出符合下列要求的C语言语句1)定义整型变量 n、m,双精度浮点数变量wf1、wf2,并且wf1 在定义时初始化为19.5。
int n,m;double wf1 =19.5,wf2;2)要求输入int型变量k、l, 并且二个变量间用“,”分隔,写出对应的输入语句Scanf(“%d,%d”,&k,&l);3)要求输出整型变量x,左对齐,域宽为5个字符,单浮点数变量 fj,域宽为8个字符,5位小数,字符变量cb,各变量间用‘,’分隔,最后为换行,写出对应的输出语句。
Printf(“%5d,%8.5f,%c\n”,x,fj,cb);4)初始a为11,循环要求初始时i为4,每次循环变量i 加1,要求循环12次,循环体中为 a 每次循环增加i,写出对应的for语句。
For(i=4;i<=16;i++){a=a+i;}定义一个学生情况的结构体,名为Student。
Struct student{ };1、为该结构体添加三个域:学号(7位整型)、姓名(20位字符串)、成绩(实型,单精度)。
Struct student{ long int xh;Char xm[20];Float cj;}2、为该结构体定义一个变量,能对三个域作初始化。
学号:1234567;姓名:杨蓉,成绩:88.5Struct student{ long int xh;Char xm[20];Float cj;}a={1234567,”杨蓉”,88.5};3、用打印语句,输出“学号”、“姓名”,“成绩”及其对应的值。
Printf(“学号=%d,姓名=%s,成绩=%f ”,a.xh, a.nam,a.cj);5)下面程序功能是打印出如下的三角形,请填空①344555666677777main(){int i,j; int i,j,k=3;for(i=3;i< =7 ;i++) for(i=1,i< =5 ;i++){for(j=0; j<=i-3 ;j++) for(j=1; j<=i ;j++) printf(“%d ”, i ); {printf(“%d ”,k );printf(“\n”);}printf(“\n”);k++;}}② @ ③ *$$ ***@@@@ *****$$$$ *******指出下列哪几个变量名是非法的?非法的原因是什么?use-ip, double,Float, 5green, #temiop,boom_Amg, _memg,there h711o $a #b写出下列算式的C语言表达式1) x*s+y 2) sin2x *(a+b) c*(a+b) (x2+y2)(x*s+y)/(c*(a+b))(Sin(x)* Sin(x)*(a+b))/(x*x+y*y)写出下列表达式的值。
1) a%5*(int)(x+y)%7/5+x设 a=2,x=15.4,y=25.72) (float)(a+b)/2+(int)++x%(int)y设a=2,b=3,x=13.8,y=7.43)写出下面程序运行的结果#include “stdio.h”main(){int n=15,a=0;while(n--) a=a+n;printf(“N=%d\n”,n);}4)读如下程序段,写出当输入x为27时的输出结果if(x>30) y=x*12;else if(x>25)y=x+12;else y=x%15;printf(“result=%d\n”,y);5)写出循环语句while(){} 和do{} while(); 在功能上主要的不同是什么?6)下面二段程序执行结果分别是什么?① j=6;k=5;while(j<=4){k=k+12+j;}printf(k=%d\n”,k);② j=6;k=5;do{k=k+12+j;}while(j<=4);printf(k=%d\n”,k);7)以下程序运行后输出什么图形?①main(){int i,j;for(i=1;i<=5;i++){ for(j=1;j<=6-i;j++)printf(“&”);printf(“\n”);}}②main(){int s,i;s=0;for(i=1;i<10;i=i+2)s+=i;//1+3+7+9printf(“%d\n”,s);}结果:____________________________③main(){char s[]=”abcdef”;strcpy(s,”hello!”); \;s[5]=’Y’printf(“%s\n”,s);}结果:_____helloY_______________________④main(){char cf[3][3]={“AAA”,”BBB”,”CCC”};int i, j;for(i=0;i<3;i++)for(j=0;j<3;j++)cf[i][j]=cf[i][j]+1;printf(“%c\n”,cf[2][1]);}结果:____________________________f(3,5);⑤int f(int m,int n){if (m>n) return(n);else if(m<n) return(m);else return(0);}main(){int a=3,b=5,x;x=f(a,b);printf(“%d\n”,x);}结果:____________________________⑦main(){int a=15,b=21,m=0;switch(b%a){case 0: m++;break;case 6: m++;case 5: m++;break;default: m++;}printf(“%d\n”,m);}结果:____2________________________⑧struct STU{char num[10];float score [3];};main(){struct STU s[3]={{“张红”,95,68,77},{“李萌”,80,90,92},{“黄炳”,100,95,90}} int i; float sum=0;for(i =0;i<3;++i){sum=sum+s[i].score[0]+ s[i].score[1]+ s[i].score[2];printf(“%s的总成绩=%6.2f”,s[i].num,sum);sum=0;}}结果:____________________________⑨void fun(int x,int y){x=x+y; y=x-y; x=x-y;printf(“%d,%d”,x, y);}main(){int x=5,y=7;fun(x,y);printf(“%d,%d”,x,y);}结果:_7,55,7___________________________1、sin(28。