第一范文网 - 专业文章范例文档资料分享平台

济南大学c语言实验答案

来源:用户分享 时间:2025/10/26 7:32:54 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

实验2 顺序结构程序设计

1. 编写程序,从键盘输入一个大写字母,将它转换为对应的小写字母后输出。

参考程序:

#include \void main() {

char ch;

printf(“\\nPlease input a capital character:”); scanf(“%c”,&ch); ch=ch+32;

printf(“\\nThe small letter is %c”,ch); }

2.编写程序,输入圆半径r,求圆周长、圆面积、圆球体积。

参考程序:

#include #include #define PI 3.14 void main() {

float r,c,area,v;

printf(“\\nPlease input the r:”); scanf(“%f”,&r); c=2*PI*r; area=PI*r*r;

v=4.0/3*PI*pow(r,3);

printf(“\\nThe circle?s perimeter is %.2f”,c); printf(“\\nThe circle?s area is %.2f”,area; printf(“\\nThe circle?s volume is %.2f”,v); }

3. 输入一个华氏温度,要求输出摄氏温度。公式为:

5c??F?32?9

输出要有文字说明,取2位小数。

参考程序:

#include void main() {

float f,c;

printf(“\\nPlease input a F temperature:”); scanf(“%f”,&f); c=5.0/9*(f-32);

printf(“\\nThe temperature is %.2f”,c); }

4. 有3个电阻r1、r2、r3并联,编写程序计算并输出并联后的电阻r。已知电阻并联公式为:

1111??? rr1r2r3

参考程序:

#include void main() {

float r,r1,r2,r3;

printf(“\\nPlease input r1、r2、r3:”); scanf(“%f%f%f”,&r1,&r2,&r3); r=1.0/r1+1.0/r2+1.0/r3; r=1.0/r;

printf(“\\nThe result is %.2f”,r); }

5.编写程序,输入三角形的三条边,计算并输出三角形的面积。(注意输入的三条边必须要能构成一个三角形) 求三角形的面积公式为:

area?s?s?a??s?b??s?c?

其中s=(a+b+c)/2。

参考程序:

#include #include void main() {

float a,b,c,s,area;

printf(“\\nPlease 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(“\\nThe area is %f”,area); }

6. 编写程序,输入梯形的上底和下底,计算并输出梯形的面积。精确到小数点

后2位,输入输出时要有文字说明。

参考程序:

#include void main() {

float x,y,h,area;

printf(“\\nPlease input the x,y,h:”); scanf(“%f,%f,%f”,&x,&y,&h); area=(x+y)*h/2;

printf(“The area is %.2f”,area); }

7. 周期为T秒的人造卫星离地面的平均高度H的计算公式为:

?1126.67?10MTH?3?R 24?其中:M=6×1024kg是地球质量,R=6.371×106m是地球半径。

编写程序,输入人造卫星的周期T,计算并输出人造卫星离地面的高度H。

参考程序:

#include #include #define PI 3.14

#define M (6*pow(10,24)) #define R (6.371*pow(10,6)) void main() {

double t,h,temp;

printf(\ scanf(\

temp=(6.67*pow(10,-11)*M*t*t)/(4*PI*PI); h=pow(temp,1.0/3)-R;

printf(\}

实验3 选择结构程序设计

1. 编写程序,输入一个正整数,判断该数是奇数还是偶数,并输出判断结果。

参考程序:

#include \void main()

{

int m;

printf(“\\nPlease input the integer(>0):”); scanf(“%d”,&m);

printf(“\\nThe integer is %d”,m); if(m%2==0)

printf(“\\nThis is a even!”); else

printf(“\\nThis is a odd!”); }

2.有一函数:

?x3?1?x??1??2??1?x?1???x?1 y??

??1?x?103x?5??5x?3log(2x2?1)?13?x?10?10?编写一个程序,用scanf函数输入x的值,输出y值。注意表达式的书写方法。

参考程序:

#include #include void main() {

float x,y;

printf(“\\nPlease input the x:”); scanf(“%f”,&x); if(x<-1)

y=pow(x,3)-1; else if(x<=1)

y=-x*x+1; else if(x<=10) y=3*x+5; else

y=5*x+3*log(2*x*x-1)-13; printf(“\\ny=%f”,y); }

3. 编写程序,输入年号,判断并输出该年是否闰年。

参考程序:

#include void main() {

int year;

搜索更多关于: 济南大学c语言实验答案 的文档
济南大学c语言实验答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0vigs0y4c303gjy5z8a0_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top