2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > c语言第一次上机作业答案 第一次上机作业参考答案

c语言第一次上机作业答案 第一次上机作业参考答案

时间:2022-07-24 03:29:24

相关推荐

c语言第一次上机作业答案 第一次上机作业参考答案

大连理工大学 c语言作业

第一次上机作业参考答案:

1. 大写字母转换成小写字母

从键盘输入一个大写英文字母,输出相应的小写字母。

例:输入 G

输出 g

#include

void main()

{ char c;

c=getchar();

if(c>='A' && c<='Z')

c+=32;

putchar(c);

}

2. 求平方根

输入1 个实数x,计算并输出其平方根(保留1 位小数)。

例:输入 17

输出 The square root of 17.0 is 4.1

#include

#include

void main()

{ float x,root;

scanf("%f",&x);

if(x>0)

root=sqrt(x);

else

printf("Input Error!\n");

printf("The square root of %.1f is %.1f\n",x,root);

}

3.温度转换

设计一个程序将华氏温度转换成摄氏温度c = 5/9(f-32)

a) 输入华氏温度(实型)

b) 输出的摄氏温度结果保留两位小数

例: Please input Fahrenheit temperature: 76.8

The corresponding Celsius temperature is 24.89

#include

void main()

{ float f,c;

scanf("%f",&f);

c = 5.0/9*(f-32);

printf("Fahrenheit %.2f is equal to Celsius %.2f\n",f,c);

}

4. 计算旅途时间

输入2 个整数time1 和time2,表示火车的出发时间和到达时间,计算并输出旅途时间。

(有效的时间范围是0000 到2359,不需要考虑出发时间晚于到达时间的情况。)

例:输入 712 1411 (出发时间是7:12,到达时间是14:11)

输出 The train journey time is 6 hrs 59 mins.

#include

void main( )

{ int time1, time2, hours, mins;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。