C language question bank (programming), Henan University of Technology, river engineering, C language, final exam, question bank(C语言
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
库(编程)河南工业大学 河工大 c语言期末考试题库)
C language question bank (programming), Henan University of
Technology, river engineering, C language, final exam, question bank(C语言题库(编程)河南工业大学 河工大 c语言期末
考试题库)
Two, programming problems
1., there is a function: when x<0, y=-1; when x=0, y=0; when x>0, y=1.
Make a program, enter the value of X, output the value of Y.
#include
Void, main ()
{
Int, x, y;
Printf ("enter x:");
Scanf ("%d", &x);
If (x<0)
Y=-1;
Else if (x=0)
Y=0;
Else
Y=1;
Printf ("y=%d", y);
}
2. enter three real numbers, arrange these three numbers in
large to small order, and output these three numbers.
#include
Void, main ()
{int, a, B, C, temp=0;
Printf ("please, input, a, B, c:");
Scanf ("%d,%d,%d", &a, &b, &c);
If (ab&&a>c)
Max=a;
If (b>a&&b>c)
Max=b;
If (c>a&&c>b)
Max=c;
Printf (the maximum value is:%d\n, Max);
}
4. programming for round area, circle circumference. The radius
of the circle is required to be input by the keyboard, and the output should be written with two digits after the decimal point.
#include
#define PI 3.1416
(main)
{
Float, R, l, s;
Printf (enter radius: \n);
Scanf ("%f", &r);
L=2*pi*r;
S=pi*r*r;
Printf ("l=%7.2f\ns=%7.2f\n", "L", "s");
}
5. [] is a bit difficult to piecewise function: when x<-10, y=|x|+5; when -10 = x = 10, y=4x-8; when x>10, y=sqrt (x).
Make a program, enter the value of X, output the value of Y.
6. write programs to determine whether a year is a leap year.
The condition for leap year is that it can be divisible by 4,
but can not be divisible by 100 or can be divisible by 400
#include
Int, main ()
{
Int, year, leap;
Scanf ("%d", &year);
If (year%4==0)
{
If (year%100==0)
{
If (year%400==0)
Leap=1;
Else
Leap=0;
}
Else
Leap=1;
}
Else
Leap=0;
If (LEAP)
Printf ("%d is", year);
Else
Printf ("%d is not", year);
Printf ("a leap year.\n");
Return 0;
}
7. enter a Fahrenheit temperature, require output Celsius temperature, output required text description, take two digits
after decimal point. The formula is c=5/9 (f-32)
#include
Int, main ()
{
Float, F, c;
Printf (enter Fahrenheit temperature: \n);
Scanf ("%f", &f);
C= (f-32) /1.8;
Printf (the corresponding Celsius temperature is:%5.2f\n, C);
}
8., there is a function: when x<1, y=|x|; when 1<=x<10, y=2x-1; when x>=10, y=3x+11.
Make a program, enter the value of X, output the value of Y.
9. input three numbers, the three numbers in ascending order, and the output of the number three.
#include
Void, main ()
{int, a, B, C, temp=0;
Printf ("please, input, a, B, c:");
Scanf ("%d,%d,%d", &a, &b, &c);
If (a>b) {temp=a; a=b; b=temp;}
If (a>c) {temp=a; a=c; c=temp;}
If (b>c) {temp=b; b=c; c=temp;}
Printf (from small to large:%d,%d,%d\n, a, B, C);
}
10. enter a character to determine if it is lowercase, and if
so, convert it into uppercase letters; if not, do not convert.
Then output the last character.
#include
#include
Void, main ()
{
Char a;
Scanf ("%c", &a);
If (islower (a))
A=a-32;
Printf ("%c\n", a);
}
11. programming cylinder volume, cylindrical surface area. The radius of the circle is required. The height of the cylinder is input by the keyboard, and the output should be written with two digits after the decimal point.
#include
Int main (int, argc, char, *argv[])
{
Float, R, h, l, s, SQ, VQ, vz;
Float pi=3.1415926;
Printf ("please enter the circle of radius r, cylinder H:");
Scanf ("%f", "%f", "&r", "&h");
L=2*pi*r;
S=pi*r*r;
Sq=4*pi*r*r;
Vq=4.0/3.0*pi*r*r;
Vz=pi*r*r*h;
Printf (circle length is l=%6.2f\n, l);
Printf (round area: s=%6.2f\n, s);
Printf ("sphere surface area: sq=%6.2f\n", sq);
Printf (sphere size: vq=%6.2f\n, VQ);
Printf (cylindrical volume: vz=%6.2f\n, VZ);
System ("PAUSE");
Return 0;
}
12. piecewise function: when x<-5, y=x+10; when -5 = x = 5, y=x^2; when x>5, y=2x-10.
Make a program, enter the value of X, output the value of Y.
13., there are three integers a, B, C, the keyboard input, the output of the smallest.
#include
Int, main ()
{
Int, a, B, C, temp, min;
Printf ("enter three integers:");
Scanf ("%d,%d,%d", &a, &b, &c);
Temp= (a
Void, main ()
{
Char c;
Printf ("input ch:");
C=getchar ();
If (c>='A'&&c<='Z')
{
C=c+32;
Printf ("%c", C);
}
Else printf ("%c", C);
}
15. enter the three sides of the triangle, the triangle area.
The formula for finding the area of a triangle is
Area=sqrt (s (S-A) (S-B) (S-C)), where s= (a+b+c) /2
#include
#include
Void, main ()
{
Float, a, B, C, s, area;
Printf (enter a, B, c:) in turn;
Scanf ("%f%f%f", "&a", "&b", "&c");
S= (float) 0.5* (a+b+c);
Area = (float) sqrt (s* (S-A) * (S-B) * (S-C));
Printf (area:%7.2f, area);
}
16. programming for 2, +4, +6, +8, +10, the value of, and output
results.
#include
Int, main ()
{
Int, n=1, sum=0, J, m=1, i;
For (i=1; i<=5; i++) {
M=1;
For (j=1; j<=2*i; j++)
M=m*j;
Sum=sum+m;
}
Printf ("sum=%d\n", sum);
Return 0;
}
17. monkeys eat peach problem. The monkey picked off some peaches on the first day and ate half of it at once. It was not satisfying yet, and ate one more.
On the second morning, I ate half of the peaches I had left, and ate one more. After every morning to eat the rest of the day before a Yibanlingyi.
By the tenth day, I'll have a peach in the morning. How many peaches were picked on the first day?.
#include
Void, main ()
{
Int day; static x1=1;
Day=10;
While (day>0)
{
X1= (x1+1) *2;
Day--;
}
Printf (peach total =%d\n, x1);
}
18., the output of all the "narcissus number", the so-called
"Narcissus count" refers to a 3 digit, the number of cubic and
equal to the number itself.
#include
int main ()
{
int i, j, k, n.
printf (水仙花数是 ");
for n = 100, n < 1000, n + +)
{
i = n / 100.
d = n / 10 * 10.
k = n% 10.
if (n = = i * i * i + j * j * j + k * k * k)
printf ("% d", (n).
}
printf (".").
return 0;
}
19.编程求1 ~ 100之间的所有素数, 并输出结果.
in stdio.h # < >
int main (void)
{
int a [100], i, j.
for (i = 0; i < 100; i + +) [i] = i + 1.
for (i = 1, i < 100; i + +).
for (j = i + 1, j < 100; j + +)
if (a [i] and a [j]% to [i] = = 0)
a [j] = 0.
for (i = 1, i < 100; i + +).
if (a [i]) printf ("% d \ t", "[i]).
return 0;
}
20.编程求1. "3. "5. "7. "9. 的值, 并输出结果.
in stdio.h # < >
int main ()
{
int n = 1, sum = 0, j, m = 1, i
for (i = 1, i = 5; i + +) {
m = 1.
for (i = 1, j = 2 * i-1, j + +)
m = m * j;
sum = sum + m;
}
printf (sum =% d \ n ", sum).
return 0;
}
21.用pi / 4?1 - 1 / 3 + 1 / 5 to 1 / 7 +...公式求pi的近似值的绝, 直到某一项对值小于10的 - 6次方为止.
in stdio.h # < >
in math.h # < >
int main ()
{
int sign = 1;
double pi = 0, n = 1, m = 1.0.
while (fabs (term) > = 1 to 6)
(pi = pi + term.
n = n + 2.
sign - sign.
term = sign / n;
} pi = pi * 4.
printf (pi =% 10.8f \ n ", pi).
return 0;
}
22.一个球从100m高度自由落下, 每次落地后又反跳回原高度的一半, 再落下, 再反弹.求它在第10次落地时共经过多少米?
# include "stdio.h"
# include "stdio.h"
main ()
{
float sn = 100.0, hn = sn / 2);
int n;
for n = 2, n = 10, n + +)
{
sn, sn + 2) * / * * / 第n次落地时共经过的米数 hp.
hn = nh / 2; / * * / 第n次反跳高度
}
printf (the total of road is% f \ n ", sn).
getch ().
}
23.输入两个正整数m和n, 求其最大公约数和最小公倍数.
in stdio.h # < >
int main ()
{
int p, r, n, m, temp.
printf (请输入两个正整数n, m ').
scanf (% d% d ", & n & m).
if (n, m)
{
temp = n;
n, m;
t = time.
}
p = n * m;
while (m! = 0)
{
r = n% m;
n, m;
m = r.
}
printf (它们的最大公约数为:% d \ n ", n).
printf (它们的最小公约数为:% d \ n ", p / n).
return 0;
}
24.利用循环, 编程求1. "2. "3. +... + 10. 的值, 并输出结果.
main ()
{
int i, j, n, sum = 0.
for (i = 1, i = 10; i + +).
{
n = 1;
for (i = 1, j = i; j + +)
n * = j;
sum + = n;
}
printf ("% d \ n", sum).
}
25.有一分数序列: 2 / 13 / 2 to 3.8 v 5.13 / 8.21 / 13., 求出
这个数列前20项之和.
in stdio.h # < >
main ()
{int i, x, y,.
float sum = 0.
x = 2.
y = 1.
for (i = 1, i < 20; i + +).
{
sum + = (float) (x).
/ / / / / / / / printf (% d% d \ n, x, y).
a = x;
x = x + y;
y = a;
}
printf (% 7.5f \ n ", sum).
}
26.求fibonacci数列前40个数.这个数列有以下特点: 第1和第2个数为1, 从第3个数开始, 该数是其前面两个数之和.
in stdio.h # < >
# define n 4.
the long number (int n)
{
if (0 = = 1 = = n n n n n n n | |) return 1;
else
in fibonacci (n - 1) + fibonacci (n - 2);
}
int main (void)
{
int i;
printf (fibonacci数列的前40项 \ n ");
for (i = 0; i < 40.
{
printf (% 10ld "fibonacci (i + +).
if (i% n = = 0) printf (".").
}
printf (".").
return 0;
}
27.一个数如果恰好等于它的因子之和, 这个数就称为完数.例如, 6的因子为1、2、3, 而6 = 1 + 2 + 3 因此6是完数.编程求1000以内所有完数.
in stdio.h # < >
void main ()
{
int i, j;
int sum.
for (i = 2); 1 (a; i + +).
{
sum = 0.
for (i = 1, j < i; j + +)
if (i% i = = 0)
sum = sum + j.
if (sum = = 1)
printf (% d是完数 \ n ", sum).
}
}
28.求s = a + aa + aa or aaa +... + (n个a) 之值.其中a是一个数字, n代
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
a的位数.例如 2 + 22 + 222 + other (此时n为5 n由键盘输入 + 22222).
in stdio.h # < >
int main ()
{
int a, n, (i = 1, sn = 0, t = 0.
printf (a, n: ");
scanf ("% d,% d, &, & n).
while (i = n).
(t = t +.
sn = ns + nt.
a = a * 10.
+ + i;
}
printf (a + aa + aaa +... =% d \ n ", sn).
return 0;
}
29.编程求100 ~ 200之间的所有素数, 并输出结果.
in stdio.h # < >
in math.h # < >
int main ()
(int n, k, i, m = 0.
for (n = 101); n = 200 n = (n + 2).
{k = sqrt (n).
for (i = 1, i = k (i + +).
if (n) i = = 0) break.
if (i) = (k + 1).
(printf ("% d", (n).
m = m + 1.
}
if (m% 10 = = 0) printf (".").
}
printf (".").
return 0;
}
30.输入一行字符, 分别统计出其中英文字母、空格、数字和其他字符的个数.
# include "stdio.h"
main ()
(char c; int i = 0; j = 0, k = 0, t = 0.
while ((c = getchar ()). (n).
{if (c > = 65 & & c = 90 | | c = 97 & & c = (i + +).
else if (c > = 48 & & c = 57) j + +.
else if (c = = 32 k +.
else l + +}
printf (i = j =% d% d% d, k = l =% d \ n, i, j, k, l).
}
31.将一个数组中的值按逆序重新存放.例如, 原来顺序为
8,6,4,3,2,0.要求改为0,2,3,4,6,8.
in stdio.h # < >
# define n 5
int main ()
{int a [n], the temp.
printf ("enter the array a: \ n");
for (i = 0; i < n; i + +).
scanf ("% d" & a [i]).
printf (array a: \ n ");
for (i = 0; i < n; i + +).
printf (% "4d", "[i]).
for (i = 0; i < n / 2; i + +).
(time = a [i].
a [i] = a [n - (i - 1).
a [n - 1] = temp;
}
printf ("nnow, array a: \ n");
for (i = 0; i < n; i + +).
printf (% "4d", "[i]).
printf (".").
return 0;
}
32.编写一个函数, 求数列1 + 1 / 2 + 1 / 3 + 1 / 4 + 1 / 4 + 1
/ n, 利用主函数调用这个函数并输出结果.
in stdio.h # < >
main ()
{
where i = 1, n = 0,.
printf (input a number: ");
scanf ("% f", & n).
while (i = n).
{
sum + = 1 / 1;
i = i + 1.
}
printf ("% f \ n", sum).
}
33.将一个二维数组int [3], [4] 的行和列的元素互换, 存到另外
一个二维数组中.
in stdio.h # < >
int main ()
{
int a [3], [4] = {{1, 2, 3, 4}, {this}, {9,10,11,12}};
int b [3] [3], (i), (j).
printf ("arrary a: \ n");
for (i = 0; i < = 2; i + +)
{
for (j = 0, j < = 3; j + +)
{
printf ("% 5d", a [i] [j]);
b [j] [i] = a [i] [j];
}
printf ("\ n");
}
printf ("array b: \ n");
for (i = 0; i < = 3; i + +)
{
for (j = 0, j < = 2; j + +)
printf ("% 5d", b [i] [j]);
printf ("\ n");
}
return 0;
}
34.利用循环输出以下图形
* * * * *
* * * *
* * *
* *
*
# include stdio.h > <
int main ()
{
int
i, j, m;
for (i = 1; in < = 5; i + +)
{
m =;
for (m = 1; m < i; m + +)
printf ("");
for (j = 0, j < = 5 - i; j + +)
printf ("*");
printf ("\ n");
}
return 0;
}
35.用冒泡排序法对输入的10个数进行降序排序, 并存入数组中.
# include stdio.h > <
int main ()
{
int a [10];
int i, j, t;
printf ("input 10 numbers: \ n");
for (i = 0; i < 10; i + +)
scanf ("% d" & a [i]);
printf ("\ n");
for (j = 0, j < 9; j + +)
for (i = 0; i < 9 - j; i + +)
if (a [i] < (a [i + 1])
{t = a [i]; a [i] = a [i + 1]; a [i + 1] = t;}
printf ("the sorted numbers: \ n");
for (i = 0; i < 10; i + +)
printf ("% d", a [i]);
printf ("\ n");
return 0;
}
36.有一个3乘4的矩阵, 要求编程序求出其中值最大的那个元素的值, 以及其所在的行号和列号.
# include stdio.h > <
int main ()
{
int i, j, ro = 0, colum = 0, max;
int a [3] [4] = {{1,2,3,4}, {5,6,7,8-tetrahydro-3,5,5,6,8,8},
{9,10,11,12}};
max = a [0] [0];
for (i = 0; i < = 2; i + +)
for (j = 0, j < = 3; j + +)
if (a [i] [j] > max)
{max = a [i] [j];
row =;
colum = j;
}
printf ("max =% d, row =% d, colum =% d \ n", max, row colum);
return 0;
}
37.用冒泡排序法对输入的10个数进行升序排序, 并存入数组中.
# include stdio.h > <
int main ()
{
int a [10];
int i, j, t;
printf ("input 10 numbers: \ n");
for (i = 0; i < 10; i + +)
scanf ("% d" & a [i]);
printf ("\ n");
for (j = 0, j < 9; j + +)
for (i = 0; i < 9 - j; i + +)
if (a [i] > a [i + 1])
{t = a [i]; a [i] = a [i + 1]; a [i + 1] = t;}
printf ("the sorted numbers: \ n");
for (i = 0; i < 10; i + +)
printf ("% d", a [i]);
printf ("\ n");
return 0;
}
38.利用循环, 输出以下图形
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
# include stdio.h > <
int main ()
{char a [5] = {'*', '*', '*', '*', '*');
int i, j, k;
char space = '';
for (i = 0; i < 5; i + +)
{printf ("\ n");
printf ("");
for (j = 1; j < = i; j + +)
printf ("% c", space);
for (k = 0; k < 5; k + +)
printf ("% c", a [k]);
}
printf ("\ n");
return 0;
}
39.输出以下杨辉三角形 (要求输出10行).
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
...
# include stdio.h > <
# define n 10
int main ()
{int i, j, a [n] [n];
for (i = 0; i < n; i + +)
{a [in] [in] = 1;
a [i] [0] = 1;
}
for (i = 2 < n; i + +)
for (j = 1; j < = 1; j + +)
a [i] [j] = a [- 1] [j + 1] a [- 1] [j];
for (i = 0; i < n; i + +)
{(j = 0, j < = i; j + +)
printf ("% 6d", a [i] [j]);
printf ("\ n");
}
printf(“\n”);
返回0;
}
40。利用循环输出以下图形
*
* * *
*****
*******
#包括< stdio. h >
国际main()
{
int,j,m;
对于(i = 1;i < 4;i + +)
{
M = i;
对(M = 1;M = 16;M + +)
printf(“”);
为(J = 0;J,2×i-1;j++)
printf(“*”);
printf(“\n”);
}
返回0;
}
41。利用循环,输出以下图形
*******
*****
* * *
*
#包括< stdio. h >
国际main()
{
int,i,j;
scanf(“%d”,和N);
为(i = 0;i <;;+(+))
{
为(J = n-1-i;J > 0;J)printf(“”);
为(J = 0;J,2 *我+ 1;j++){ int k = J;如果(K,25)% = 26;
printf(“%c”、“*”+ K);}
printf(“\n”);
}
返回0;
}
42。求一个3×3的整型矩阵对角线元素之和。
#包括< stdio. h >
main()
{
int [ 3 ] [ 3 ],i,j,和,0;
printf(“请输入数组元素:(3×3)\n”);
对于(i = 0;i < 3;i +)
对于(j,0;j,3;j + +)
scanf(“%d”,和一个[我] [ J ]);
printf(“\n”);
printf(“数组为:\n”);
对于(i = 0;i < 3;i +)
{(j,0;j,3;j + +)
printf(“4D”,一个[我] [ J ]);
printf(“\n”);
}
printf(“\n”);
printf(“对角线的和:\n”);
对于(i = 0;i < 3;i +)
对于(j,0;j,3;j + +)
如果(我= = = = J J | | 2-I)
和[ i ];
printf(“%d”,总和);
}
43。编写程序,将两个字符串连接起来,不要使用strcat函数。
国际main()
{
一个字符串=“qwet”* b =“伟”;
字符C [ 20 ];
int,j;
对于(i = 0,j = 0;*(a + i);i +,j + +)
c(= i);
用于(i = 0;*(b + i);i + +,j + +)
c(= i);
c =“0”;
对于(i = 0;c [ i ];i +)
printf(“%c”,C [我]);
}
44。写一个函数,求两个整数中的较大者,用主函数调用这个函数,
并输出结果,两个整数由键盘输入。
#包括< stdio. h >
国际maxnum(int,int b)
{
返回(A,B,)甲:乙);
}
无效main()
{
a,b,max;
printf(“输入两个数~“n);
scanf(“%d %d”,&,& B);
马克斯= maxnum(A,B);
printf(“麦克斯:%d\n”,最大);
}
45。编写两个函数分别求两个整数的最大公约数和最小公倍数,在主
函数中调用这两个函数,并输出结果,两个整数由键盘输入。
#包括< stdio. h >
int HCF(int,int);
液晶显示器(int,int,int);
无效main()
{
u,v,h,L;
scanf(“%d,%d”,与U和V);
H = HCF(U,V);
printf(“h.c.f = %d\n”,H);
L =液晶显示器(U,v,H);
printf(“l.c.d = %d”,L);
}
int HCF(int,int V)
{
整数,r;
如果(v)
{
T = u;
u,v;
V,T;
同时((r = u v)~= 0)
{
u,v;
V,R;
}
返回(V);
}
液晶显示器(int,int,int)
{
返回(u * v / H);
}
46。输出左边图案。
„
.....
.......
.....
„
。
#包括< stdio. h >
国际main()
{ i,j,k;
对于(i = 0;i < 3;i + +)
{(j = 0, j < = 2 - i; j + +)
printf ("");
for (k = 0; k < = 2 * i; k + +)
printf ("*");
printf ("\ n");
}
for (i = 0; i < = 2; i + +)
{(j = 0, j < = i; j + +)
printf ("");
for
(k = 0; k < = 4 - 2 * i; k + +)
printf ("*");
printf ("\ n");
}
return 0;
}