- 155
- 0
- 约6.54万字
- 约 100页
- 2020-10-21 发布于湖南
- 举报
1.已知三角形的三边长为a,b,c,计算三角形面积的公式为:
area=sqrt(s(s-a)(s-b)(s-c)),其中 s=(a+b+c)/2。
试编程从键盘输入 a,b,c的值(假设 a,b,c的值可以保证其构成一个三角形),计算并输出三角形的面积。
**输入格式要求:%f,%f,%f 提示信息:Input a,b,c:
**输出格式要求:area = %.2f\n
程序运行示例如下:
Input a,b,c:3,4,5
area = 6.00
答案:#includestdio.h
#includemath.h
int main(void)
{
float a, b, c, s, area;
printf(Input a,b,c:);
scanf(%f,%f,%f, a, b, c);
s = (a + b + c) / 2;
area = sqrt(s*(s - a)*(s - b)*(s - c));
printf(area = %.2f\n, area);
return 0;
}
-----------------1
2.从键盘任意输入一个 4位整数,编程计算并输出它的逆序数.例如:输入 1234,分离出千位 1、百位2、十位 3和个位 4,然后计
算 4*1000+3*100+2*10+1=4321,并输出 4321。
**要求输入提示信息为:无
**要求输入格式为: %d
**要求输出格式为:%d
程序运行示例如下:
1234 此处为输入
4321 此处为输出
答案:
#includestdio.h
int main(void)
{
int a, b, c, d,e;
scanf(%d,a);
b = a/1000;
c = a%1000/100;
d = a%100/10;
e = a%10;
a = e*1000+d*100+c*10+b;
printf(%d,a);
return 0;
}
--------------2
3.有关输入输出问题。
输入为:12a↙
b↙
运行结果为:1,2,a,b,123.300000,65535
请改正程序中的错误,使它能得出正确的结果。
#include stdio.h
main()
{
int b;
unsigned short a = 65535;
short k = a;
char c, d;
int f, g;
b = (1234.0 - 1) / 10;
scanf(%c, c);
scanf(%c, d);
scanf(%d, f);
scanf(%d, g);
printf(%c,%c,%c,%c,%f,%d, c, d , f, g, b, k);
}
答案:#include stdio.h
main()
{
double b;
int a = 65535;
char c, d;
int f, g;
b = (1234.0 - 1) / 10;
scanf(%c, c);
scanf(%c, d);
scanf(%c\t, f);
scanf(%c, g);
printf(%c,%c,%c,%c,%f,%d, c, d , f, g, b, a);
}
--------3
4.输入一行字符,统计其中的英文字符、数字字符、空格字符,以及其他字符的个数。请找出以下程序的错误,并改正之。
#include stdio.h
#include string.h
#define ARR_SIZE = 80;
main()
{
charstr[ARR_SIZE];
int len, i;
int letter=0,digit=0,space=0,other=0;
printf(请输入一个字符串:);
gets(str);
len = strlen(str);
for(i=0; ilen; i++)
{
if(a=str[i]=z || A=str[i]=Z)
{
letter ++;
}
elseif(0=str[i]=9)
{
digit ++;
}
elseif(str[i]= )
{
space ++;
}
else
other ++;
}
printf(英文字符数:%d\n, letter);
printf(数字字符数:%d\n, digit);
printf(空格数:%d\n, space);
printf(其他字符数:%d\n, other);
}
答案 :#include stdio.h
#include string.h
#define ARR_SIZE 80
main()
{
charstr[ARR_SIZE];
int len, i;
int letter = 0, digit = 0, space = 0, other = 0;
printf(请
您可能关注的文档
最近下载
- (高清版)C-H-T 9012-2011 基础地理信息数字成果数据组织及文件命名规则.pdf VIP
- Unit6 Numbers in life A let's learn(课件) 人教PEP版(2024)英语三年级下册.pptx VIP
- 2026年重庆高考物理考试卷及答案.docx VIP
- 2025年新疆高考语文试卷及答案.docx VIP
- 工程断裂力学课件.ppt
- 部编版六年级语文下册导学案(全册).docx VIP
- 大足石刻宝顶山景区讲解词(完整版).pdf VIP
- 最新2026年时事政治题单招标准卷.docx VIP
- 伟思医疗公司2019年财务分析研究报告.docx
- 外国名家哲理短文40篇重点.doc
原创力文档

文档评论(0)