大一的c与语言期末试题及答案,大一c语言期末试题及参考答案

您所在的位置:网站首页 大一c语言期末考试试题及答案汇总 大一的c与语言期末试题及答案,大一c语言期末试题及参考答案

大一的c与语言期末试题及答案,大一c语言期末试题及参考答案

2024-07-15 19:40| 来源: 网络整理| 查看: 265

20042004 级信息学院级信息学院 C C 语言设计语言设计 考试试题考试试题 一 判断下列语句或程序的对错 10 分 1 int x y z 0 y z 没有定义 2 include 不能有分号 开头的结尾均不能有分 号 3 printf s n c language 4 float a 100 int p a 数据类型不匹配 5 char str 20 6 int data 4 0 1 2 3 4 五个元素 但是只有四个单元 7 float x 1 45e 310L 数值越界 8 int xyz 1 2 9 int x xae 10 int p a 2 3 p a 数据类型不匹配 二 计算下列表达式的值 10 分 设 unsigned int a 10 b 17 c 5 d 3 float f 1 f b c 3 0 2 a b c 1 sub 添加函数原型声明添加函数原型声明 main float a b float add reasult sub result scanf f f a b add result calculate a b 应该直接定义为变量应该直接定义为变量 floatfloat temp temp sub a a b b sub a a b b sub a a b b temp a a b b return temp returnreturn temptemp 2 统计 N 个字符中大写字母和数字字符的个数 include define N 5 Count charCount char str int str int result result 添加函数声明添加函数声明 main char string N 80 char i int Capital Count 0 0 Num Count 0 0 需要初始化为需要初始化为 0 0 for i 0 i N i scanf s 去掉去掉I N I Capital Count Count string I Printf Capital count d numbercount d n Capital Count Num Count Count char str int result int temp I intint temp 0temp 0 i i temptemp 应该初始化为应该初始化为 0 0 for I 0 I A return temp 四 程序填空 10 分 答案参考书中 p85 86 1 利用公式 sin x x x 3 x 3 x 0 5 n 20 include main float y s x d t int n I j scanf d f s 1 0 for I 2 I n I d t for j 1 j d t s 1 s y 2 利用库函数 char strstr char sl char s2 在给定字符串中查找 子串最后 最右 一次出现的位置 如果 S2 并没有出现在 S1 的任何地方 函 数返回一个 NULL 指针 如果第二个参数是一个空字符串 函数就返回 S1 注 库函数 char strstr char s1 strstr char s1 char s2 这个函数在 S1 中查找子字符 串 S2 第一次出现的起始位置 并返回一个指向该位置的指针 如果 S2 并没有出 现在 S1 的任何地方 函数返回一个 NULL 指针 如果第二个参数是一个空字符 串 函数返回 S1 答案见书中 p196 197 include include void main void char str 80 ABCdabcdfgabc char p p my strrstr str abc printf s n p p my strrstr str printf s n p char my strrstr char s1 char s2 char last char current if last current While last current current return last 五 写输出结果 20 分 1 include void fun int int void main int a 5 6 7 8 i fun a 4 for i 0 i 4 i printf d n a i void fun int b int n int i for i 0 i n i b i i 2 return 0 2 4 6 2 include void main int i j max int row 0 column 0 int a 3 3 1 2 3 2 3 4 9 4 7 max a 0 0 for i 0 i 3 i for j 0 jmax max a i j row i 1 column j 1 printf max d row d column d n max row column 书中例题 5 5 p123 max 9 row 3 column 1 3 include int n 1 void func void main static int x 5 int y y n printf main x d y d n d n x y n func printf main x d y d n d n x y n void func static int x 4 int y 10 x x 2 n n 2 y y n printf func x d y d n d n x y n main x 5 y 1 n 1 func x 6 y 13 n 3 main x 5 y 1 n 3 4 include include struct person char name 20 int count void main struct person leader 3 li 0 zhang 0 wang 0 char name 20 m n for m 1 m 7 m scanf s name for n 0 n 3 n if strcmp name leader n name leader n count break printf n for m 0 m 3 m printf s d n leader m name leader m count 当程序运行时 键入情况如下 Li Wang Lei Li Wang Zhang 写出程序的输出结果 基本上是书中例题 Li 2 Zhang 1 Wang 2 5 include include void main char name capital index large small int a b n 4 char temp for a 0 a n 1 a for b a 1 b0 temp name a name a name b name b temp 在此之前是书中的例题在此之前是书中的例题 7 197 19 for a 0 a n a printf s n name a a 输出时应该能够识别指针及偏移情况输出时应该能够识别指针及偏移情况 capital ndex rge ll 六 编写程序 35 分 1 求一元二次方程 ax bx c 0 的根 实系数 a b c 从终端输入 只考虑两 2 个不同实根和两个相同的实根 9 分 书中例题 3 4 p66 67 include include void main float a b c float x1 x2 float x3 x4 float m printf input the numbers a b c scanf f f f if a 0 printf the input is error n return m b b 4 a c if m 0 x1 b sqrt m 2 a x2 b sqrt m 2 a printf x1 2f x2 2f n x1 x2 else if m 0 x1 x2 b sqrt m 2 a printf x1 x2 2f n x1 else x3 b 2 a x4 sqrt m 2 a printf x1 2f 2fi n x3 x4 printf x2 2f 2fi n x3 x4 2 编写一个函数 求 s a aa aaa aaaaaaaaa a 其中 a 是一 个数字 例如 2 22 222 2222 此时 n 4 主函数 a 和 n 的输入 调用所函数 和输出所求的 累加和 编写的函数完成计算 9 分 注意 不得使用全局变量 注意程序结构 书中习题 3 4 16 include include long Cal long a long n main long sn 0 long a n printf please input a n scanf d d sn Cal a n printf a aa aaa aa a ld n n sn long int Cal long a long n int i long sn 0 m 0 for i 0 i n i m m 10 a sn m return sn 3 从十个字符串中找出所要的某个字符串 若能找到则把他删除 然后输出 新字符串 若未找到则输出 can not fond 9 分 include include main char s 10 80 char s2 80 int i j int num 0 printf please enter 10 string n for i 0 i 10 i gets s i printf please enter s2 string gets s2 for i 0 i 10 i if strcmp s i s2 0 for j i j 9 num j strcpy s j s j 1 i num for i 0 i 10 num i puts s i 4 一个班有 N 个同学 修 5 门课从键盘输入他们的性名 学号 性别和成绩 1 按平均成绩从高到底打印全班的成绩单 2 求第三门课的平均分 3 找出平均分在 90 以上或全部功课在 85 以上的女生 要求 输入 输出 计算 排序和查找分别用函数实现 主函数只是调用这些 函数 不得使用全局变量 include define N 5 struct Student char name 20 int number int sex float score 5 float aver void Input struct Student stu void Average struct Student stu float aver void Sort struct Student stu void Search struct Student stu float score main struct Student stu N float score 85 0 float aver3 Input stu Sort stu Average stu printf average3 is 2f n aver3 Search stu score void Input struct Student stu int i j float aver 0 for i 0 i N i aver 0 printf please enter name gets stu i name printf please enter number sex scanf d d printf please enter score 5 for j 0 j 5 j scanf f aver stu i score j stu i aver aver 5 getchar void Sort struct Student stu int i j struct Student temp for i 0 i N 1 i for j i 1 j N j if stu i aver stu j aver temp stu i stu i stu j stu j temp printf Name Numb Sex score 5 aver n for i 0 i N i printf 8s d d 2f 2f 2f 2f 2f 2f n stu i name stu i number stu i sex stu i score 0 stu i score 1 stu i score 2 stu i score 3 s tu i score 4 stu i aver void Average struct Student stu float average3 float sum3 0 int i for i 0 i90 score 85 n printf Name Numb Sex score 5 aver n for i 0 i N i for j 0 jscore if stu i aver 90 0 printf n n

展开阅读全文



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3