没有合适的资源?快使用搜索试试~ 我知道了~
C语言程序简单例子.doc
0 下载量 129 浏览量
2023-07-05
13:05:48
上传
评论
收藏 84KB DOC 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/88000652/0001-dce29bfa947e8f850ca5a0fe89688719_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
21页
C语言程序简单例子.doc
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/88000652/bg1.jpg)
.
实用文档.
实验二参考答案
1.输入两个整型数字,输出他们的和。
#include<stdio.h>
main()
{
int a, b, sum;
scanf(“%d%d〞, &a, &b);
sum=a+b;
printf(“a+b=%d〞, sum);
}
2.输入两个实型数,输出他们的和与乘积。
#include<stdio.h>
main()
{
float a, b, sum, product;
scanf(“%f%f〞, &a, &b);
sum=a+b;
product=a*b;
printf(“a+b=%f, a*b =%f〞, sum, product);
}
3.求方程 的根〔设
04
2
�� acb
〕〔其中 a,b,c 的值由键盘输入〕。
#include<stdio.h>
#include<math.h>
main()
{
float a, b, c, dt, x1, x2;
scanf(“%f%f%f〞, &a, &b, &c);
dt=sqrt(b*b-4*a*c);
x1=(-b+dt)/(2*a);
x2=(-b-dt)/(2*a);
printf(“x1=%f, x2 =%f〞, x1, x2);
}
0
2
��� cbxax
![](https://csdnimg.cn/release/download_crawler_static/88000652/bg2.jpg)
.
实用文档.
4.鸡兔同笼,鸡兔总头数为 h,总脚数为 f,求鸡兔各多少只?〔h 和 f 的值由键盘输
入,输出鸡和兔的头数〕
#include<stdio.h>
main()
{
int h, f, x,y;
scanf(“%d%d〞, &h, &f);
x=2*h-f/2;
y=f/2-h;
printf(“x=%d, y =%d〞, x, y);
}
![](https://csdnimg.cn/release/download_crawler_static/88000652/bg3.jpg)
.
实用文档.
实验三参考答案
1.输入三个数 a、b、c,要求按由小到大的顺序输出。
#include<stdio.h>
main()
{
float a,b,c,t;
scanf(“%f,%f,%f〞,&a,&b,&c);
if(a>b)
{
t=a; a=b; b=t;
}
if(a>c)
{
t=a; a=c; c=t;
}
if(b>c)
{
t=b; b=c; c=t;
}
printf(“%f,%f,%f〞,a,b,c);
}
2.编写程序,输入三角形三边 a、b、c,判断 a、b、c 能否构成三角形,假设不
能那么输出相应的信息,假设能那么判断组成的是等腰、等边、直角还是一般三角形。
(1)
#include<stdio.h>
main()
{
float a,b,c,t;
scanf(“%f,%f,%f〞,&a,&b,&c);
if(a>b)
{t=a; a=b; b=t;}
if(a>c)
{t=a; a=c; c=t;}
if(b>c)
{t=b; b=c; c=t;}
![](https://csdnimg.cn/release/download_crawler_static/88000652/bg4.jpg)
.
实用文档.
if(a+b>c)
{
if(a==b||b==c)
{
if(a==c) printf(“等边三角型〞);
else if(c*c==a*a+b*b) printf(“等腰直角三角形〞);
else printf(“一般等腰三角形〞);
}
else if(c*c==a*a+b*b) printf(“一般直角三角形〞);
else printf(“一般三角形〞);
}
else printf(“不构成三角形〞);
}
(2)
#include<stdio.h>
main()
{
float a,b,c,t;
scanf(“%f,%f,%f〞,&a,&b,&c);
if(a>b)
{t=a; a=b; b=t;}
if(a>c)
{t=a; a=c; c=t;}
if(b>c)
{t=b; b=c; c=t;}
if(a+b<=c) printf(“不构成三角形〞);
else if(a==b && b==c && a==c) printf(“等边三角型〞);
else if(a==b && c*c==a*a+b*b) printf(“等腰直角三角形〞);
else if (a==b) printf(“一般等腰三角形〞);
else if(c*c==a*a+b*b) printf(“一般直角三角形〞);
else printf(“一般三角形〞);
}
3.编程实现以下函数
x (x<1)
y= 2x-1 (
101 �� x
)
剩余20页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
黑色的迷迭香
- 粉丝: 731
- 资源: 4万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)