C语言程序设计_配套习题_答案
《C语言程序设计》配套习题集
答案
李忠月 2010-5-10
目录
概述....................................................................................................................................2 类型、运算符与表达式...................................................................................................19 分支结构..........................................................................................................................21 循环结构..........................................................................................................................26 函数..................................................................................................................................36 数组..................................................................................................................................46 C预处理器.......................................................................................................................59 指针..................................................................................................................................60 结构..................................................................................................................................65 位运算..............................................................................................................................76 文件..................................................................................................................................77
概述
一、
1
单项选择题。
2
3
4
5
6
7
8
9
10
D
11
B
12
A
13
A
14
C
15
D
16
B
17
A
18
B
19
B
20
A
21
D
C
A
B
C
C
C
C
C
A 二、
程序设计题。
1.
#include<stdio.h> int main() { printf("%d\n", EOF); return 0; } 2.
#include<stdio.h> int main() { int a, b;/*变量的声明*/ scanf("%d%d", &a, &b);/*输入两个整数*/ /*求两个整数的和, 乘积, 差和商, 并且输出*/ printf("%d %d %d %d\n", a+b, a*b, a-b, a/b); return 0; } 3.
#include <stdio.h> #include <math.h> int main ()
{ double x1,y1,x2,y2; double a,b,c; scanf("%lf %lf %lf %lf", &x1,&y1,&x2,&y2); a = (x1-x2)*(x1-x2); b = (y1-y2)*(y1-y2); c = sqrt(a+b); printf("%.2lf\n",c); return 0; } 4.
/* count blanks, tabs, and newlines */ #include<stdio.h> int main() { int c, nb=0, nt=0, nl=0; while((c=getchar())!=EOF){ if(c==' ') ++nb; if(c=='\t') ++nt; if(c=='\n') ++nl; } printf("%d %d %d\n", nb, nt, nl); return 0; } 5.
#include<stdio.h> #include<math.h> int main() { int i=1; while( !(i%3==1 && i%5==3 && i%7==5 && i%9==7)) i++; printf("%d\n", i); return 0; }
6.
#include <stdio.h> #include <math.h> int main() { int i; double sum=0; for(i=2; i<=10; i++) sum=sum+sqrt(i); printf("%.10f\n", sum); return 0; } 7.
#include<stdio.h> int main() { float s=100, h=100; int i; h=s/2; for(i=2; i<=10; i++){ s=s+2*h; h=h/2; } printf("%.2f\n",s); return 0; } 8.
#include<stdio.h> #include<math.h> int main() { float s=1, t=1, i=3; while(fabs(1/t)>=1e-6) { t = -t * (i-1) * i; s = s + 1/t; i += 2; } printf("%f\n", s); return 0;
} 9.
#include<stdio.h> #include<math.h> int main() { double t=1, sum=1, pi=0; int i=1, k=1; while(fabs(t)>=1e-6){ i = i+2; t = 1.0/i; k=-k; sum = sum + k*t; } pi=4*sum; printf("%f\n", pi); return 0; } 10.
#include<stdio.h> #include<math.h> int main() { double x=27; int n=2; while( !( pow(27, 1.0/(2*n))<1.00001 && pow(27, 1.0/(2*(n-1)))>1.00001) ) n++; printf("%d\n", n); return 0; } 11.
#include <stdio.h> #include <math.h> int main() { float y=1.05; int n=1; while(!(pow(1.05, n)<1e6 && pow(1.05, n+1)>1e6)) n++; printf("%d,%.3f\n", n, pow(1.05, n));
} 12.
#include <stdio.h> #include <math.h> int main() { double s=0, a=81; int i; for(i=1; i<=30; i++){ s=s+a; a=sqrt(a); } printf("%.3f\n",s); return 0; } 13.
#include <stdio.h> int main() { int a, b, i; int asum, bsum;
for(a=6; a<=5000; a++) { asum=0; for(i=1; i<a; i++)/*求a的因子之和asum*/ if(a%i==0) asum=asum+i; b=asum;/*a的因子和等于b*/ bsum=0; for(i=1; i<b; i++)/*求b的因子之和bsum*/ if(b%i==0) bsum=bsum+i; /*判断b的因子和是否等于a, 并且a不等于b*/ if(bsum==a && a!=b) printf("%d,%d\n", a, b); }
} 14.
#include<stdio.h> #include<math.h> int main() { int x, y, x1, y1; double z, z1; z1=10*cos(0-4)+5*sin(0-2); x1=0; y1=0; for(x=0; x<=10; x++) for(y=0; y<=10; y++) { z=10*cos(x-4)+5*sin(y-2); if(z<z1){ z1=z; x1=x; y1=y; } } printf("%d,%d\n", x1, y1); return 0; } 15.
#include <stdio.h> int main() { int a,b,c; int count=0; for(a=1; a<=100; a++) for(b=1; b<=100; b++) for(c=1; c<=100; c++) if((a*a+b*b)==c)/*注意不要写成c/(a*a+b*b)==1*/ count++; printf("%d\n", count); return 0; } 16.
#include<stdio.h> #include<math.h> int main() { int x, y, z, rslnum=0; int k=(int)sqrt(2000); for(x=-k; x<=k; x++) for(y=-k; y<=k; y++) for(z=-k; z<=k; z++) if(x*x+y*y+z*z==2000) rslnum++; printf("%d\n",rslnum); return 0; } 17.
#include<stdio.h> #include<math.h> float f(float); int main() { float max, …… 此处隐藏:4241字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [高中教育]电子线路高频非线性部分2.1
- [高中教育]中班美术活动——我的小手
- [高中教育]常用三极管参数大全
- [高中教育]计算机常见故障及解决办法
- [高中教育]风机基础环水平度控制方法探讨
- [高中教育]机械安全工程(专升本)阶段性作业3
- [高中教育]2009年安徽省高考语文考试说明刍议
- [高中教育]unit5 let's eat公开课教案设
- [高中教育]计算机网络原理课后习题答案
- [高中教育]2016-2022年中国新能源市场研究与投资
- [高中教育]2015-2020年中国会议行业市场评估及投
- [高中教育]经销商大会峰会主持人串词开场白
- [高中教育]2014新版北师大数学三年级上册小熊购物
- [高中教育]七年级第一学期体育与健康全套教案
- [高中教育]第三章:国际金融市场
- [高中教育]六年级下册数学单元测试-2.比例 北师大
- [高中教育]2016年上海海事大学法学院624刑法之《
- [高中教育]中国碳化钙产业竞争现状及未来五年投资
- [高中教育]网络时代,我们怎么玩
- [高中教育]圆锥曲线——高中数学基础知识与典型例
- 高集医院世界艾滋病宣传日活动方案
- 苏教版六年级英语上册期末试卷含答案
- 全民枪战生化英雄模式幽灵怎么玩 生化
- 灿烂的宋元文化一导学案
- 第2章货币资金与应收款项
- 北师大版八年级下册数学第三章《分式》
- 浅析高分子材料成型加工技术
- 华南理工大学2013年度共青团先进集体及
- 教师资格科目二小学教案模板(共合集)
- 工程扩建可研报告
- 中华人民共和国海事局2014年度招录公务
- 提高农村小学生作文能力的教学尝试
- 徒手心肺复苏术操作步骤
- 毛概试题库7-15章
- 2014-2015学年度(上)初中班主任工作计
- 企业驾驶员安全生产责任书
- 第07章 不等式测试题-2016年高考文科数
- 医疗器械经营企业工作程序
- 考研英语必背36篇_彩版_精华
- 初中9月13-15假期作业 (1)




