C语言保留答案界面,C语言练习题(答案).doc

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

答案:#include

#include

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 此处为输出

答案:

#include

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

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

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

#include

?

#define ARR_SIZE = 80;?

?

main()

{

????char str[ARR_SIZE];

????int? len, i;

????int? letter=0,digit=0,space=0,other=0;

?

????printf("请输入一个字符串:");

????gets(str);

?

????len = strlen(str);???

?

????for (i=0; i

????{

????????if (a=

????????{

????????????letter ++;??

????????}???????????????

????????else

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值