版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include <stdio.h> main() (const double pi = 3.14159;double r;double circum;double area;printf("Input r:"); scanf("%lf", &r); circum = 2 * pi * r; area = pi * r * r; printf("printf WITHOUT width or precision specifications:n"); printf("circumference = %f,
2、 area = %fn", circum, area);printf("printf WITH width and precision specifications:n"); printf("circumference = %7.2f, area = %7.2fn", circum, area); 使用const常量定义圆周率 pi (取值为3.14159),编程从键盘输入圆的半径r,计算并输出圆的周长和面积.输出的数据保存两位小数点.*输入格式要求:"lf"提示信息:"Input r:" *输出格式要求
3、:"printf WITHOUT width or precision specifications:n" "circumfer ence = %f, area = %fn" "printf WITH width and precision specifications:n" "circumfere nce = %7.2f, area = %7.2fn"程序运行例如如下: Input r:5.3 printf WITHOUT width or precision specifications: circumfere
4、nce = 33.300854, area = 88.247263 printf WITH wid th and precision specifications: circumference = 33.30, area = 88.25#include<stdio.h> main()(int a,b,c;double p,q,x1,x2;printf("Please enter the coefficients a,b,c:");scanf("%f,%f,%f",&a,&b,&c);p=-b/a;q=(bA2-4ac)
5、A0.5/(2a);x1=p-q;x2=p+q;#include<stdio.h>Main()(int a,b,c;double p,q,x1,x2;printf("Please enter the coefficients a,b,c:");scanf("%f,%f,%f",&a,&b,&c);p=-b/a;q=(bA2-4ac)A0.5/(2a);x1=p-q;x2=p+q;)计算输入的两个整数的和.*输入格式要求:"d提示信息:请输入第一个整数:""请输入第二个整数:"*输
6、出格式要求:"d + %d = %dn"程序运行例如如下: 请输入第一 个整数:34请输入第二个整数: 56 34 + 56 = 90#include <stdio.h> int main()(int n1;定义第一个整型变量n1int n2;定义第一个整型变量n2printf("请输入第一个整数:");务必养成好习惯:任何输入前先给出输入提示!scanf("%d", &n1);接收第一个整数 n1printf("请输入第二个整数:");务必养成好习惯:任何输入前先给出输入提示!scanf(&q
7、uot;%d", &n2);接收第二个整数 n2printf("%d + %d = %dn", n1, n2, n1 + n2);/*每一个格式限制符 d限制后面的一项,第一个 d限制n1 ,第二个d限制n2第三个限制n1+n2 , %用于限制输出项以十进制有符号整数的形式输出,其它的格式限制字符串中的字符,如+,=等原样输出,n为换行符*/return 0; )学校有近千名学生(大于等于900,小于1000),在操场上排队,5人一行余2人,7人一*输出格式要求:"there a行余3人,3人一行余1人,编写一个程序求该校的学生人数.re %d
8、students in the groundn"#include <stdio.h> int main()int n;for | (n = 900; n < 1000; n+)"|if (n % 5 = 2 && n % 7 = 3&& n % 3 = 1)printf("there are %d students in the groundn", n);)(假设对折一弓厚度为 0.1mm的纸,请问要对折多少次才能使纸的厚度从地球到达月球(假 设地球到月球的距离为30万km)?*输出格式要求:"
9、%d"#include <stdio.h>#include <math.h>int main() printf("%d", (int)ceil(log10(3.0) + 12) / log10(2.0);return 0;请使用short int型的变量计算两个 7位十进制整数的和,要求使用尽可能少的变量.* *输入格式要求:"a = %3hd%4hd, b = %3hd%4hd"* *输出格式要求:"a + b = %d"程序运行例如如下:a = 1234567,b = 7654321输出a + b
10、 = 8888888#include <stdio.h>int main()short int d, m, c, n;scanf("a = %3hd%4hd, b = %3hd%4hd", &d, &m, &c, &n);printf("a + b = %d", (d + c) * 10000 + m + n);return 0;华氏和摄氏温度的转换公式为:C = 5/9 x (F-32)其中,C表示摄氏温度,F表示华氏温度.要求:华氏0 丁300 下,每隔20 丁输出一个华氏温度对应的摄氏温度值.* *输入提
11、示信息要求:无* *输入数据格式要求:无* *输出数据格式要求:"4.0f%10.1fn"(第一个浮点数为华氏温度,第二个浮点数为摄氏温度)#include <stdio.h>int main()int upper, step;float f = 0, c;upper = 300;step = 20;while (f <= upper)c = 5.0 / 9 * (f - 32);printf("%4.0f%10.1fn", f, c);f = f + step;)return 0;编程输出以下形式的乘法九九表:1*1= 1 2*1=
12、2 2*2= 4 3*1= 3 3*2= 6 3*3= 9 4*1 =4 4*2= 8 4*3=12 4*4=16 5*1= 5 5*2=10 5*3=15 5*4=20 5*5=25 6*1= 6 6*2=12 6* 3=18 6*4=24 6*5=30 6*6=36 7*1= 7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=498*1= 8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 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=
13、81 *输出格式要求:"%1d*%1d=%2d #include <stdio.h> main() int i,j;for(i=1;i<=9;i+)for(j=1;j<=i;j+)-1printf("%d*%d=%2d ",i,j,i*j);printf("n");小明今年12岁,他母亲比他大 24岁.编写一个程序计算小明的母亲在几年后比小明的年 龄大一倍,那时他们两人的年龄各是多少*输出格式要求:"year=%dn" "mingAge=%dn" "motherAge=%
14、dn" 程序运行例如如下:year=12mingAge=24motherAge=48#include <stdio.h> int main() int mingAge, motherAge, year;mingAge = 12;motherAge = mingAge + 24;year = 1;while (motherAge + year) != 2 * (mingAge + year) year = year + 1;)printf("year=%dn", year);printf("mingAge=%dn", mingAge
15、+ year);printf("motherAge=%dn", motherAge + year);return 0;)用二维数组作为函数的参数,实现并输出矩阵的转置和转置后矩阵副对角线元素之和.按如下函数原型编程计算. 其中n的值由用户从键盘输入. 使用ProduceMatrix函数生成n阶方 阵,以start值作为矩阵的第一个元素 all ,每行下一个元素比该行上一个元素大1,每行第一个元素比上一行最后一个元素大1.例如n=3,start=3时ProduceMatrix生成的矩阵为:3456789 1011m和n的取值范围为1,30.函数原型为void Transpos
16、e(int a口N,int n);void ProduceMatrix(int a口N,int n,int start);void PrintMatrix(int atN, int n);int SumCounterDiagonal(int aN,int n); / 求矩阵副对角线元素之和 输入提示信息:"Input n:n" "Input %d*%d matrixs start element:n 输入格式:"d"输出提示信息和格式:"The transposed matrix is:n""The sum of
17、the matrix-counter-diagonal is:%dn"输出格式(输完矩阵的一行要换行):"4d注意除了 PrintMatrix外的输入输出均在 main函数里面#include<stdio.h>#define N 30void Transpose(int a口N, int n);void ProduceMatrix(int a口N, int n, int start);void PrintMatrix(int a口N, int n);int SumCounterDiagonal(int aN, int n);int main() int n ,
18、sum = 0, start = 0;int aNN = 0;/1printf("Input n:n");scanf("%d", &n);printf("Input %d*%d matrixs start element:n", n, n);scanf("%d", &start);/1ProduceMatrix(a, n, start);Transpose(a, n);/1printf("The transposed matrix is:n");PrintMatrix(a, n);/1sum = SumCounterDiagonal(a, n);printf("The sum of the matrix-counter-diagonal is:%dn", sum); return 0; void Produc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年广东省华南理工大学环境设计专业室内设计原理综合测试卷及答案
- 财会岗2026面试模拟练习自测卷含答案含解析配套答题思路
- 财会岗2026面试习题汇编含答案解析配套思路
- 综合岗2026事业单位面试模拟练习含答案含解析
- 2026年矿山安全法律法规培训课件
- 新消费品牌如何用好企业软文投放平台?2026年10月实战路径
- 2026印刷技能笔试试题及答案
- 2026年受限空间测试题库及答案
- 2026专升本政治试题及答案
- 2026年全国肿瘤防治宣传周科普知识竞赛考试题库及答案
- 氩弧焊作业安全交底
- 桥梁养护科学决策工作制度
- 建筑垃圾减量化监理监督实施细则
- 骨科术后加速康复营养支持方案
- 易制毒、易制爆危险化学品盗抢破坏和丢失事故应急预案
- 分级诊疗与肿瘤全程管理策略
- 中国海洋石油校招笔试题及答案
- 中文创意写作教程 课件 第一章 小说写作
- 2025年wset二题库及答案
- 雨课堂在线学堂《创新思维与战略管理》作业单元考核答案
- 学堂在线 大数据机器学习 章节测试答案
评论
0/150
提交评论