代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
输入三条线段的长度,判定它能否组成一个三角形
作者:
Dezai.CN
/ 发布于
2011/7/8
/
882
<div><span style="color: #0000ff" color="#0000ff"> <div class="cnblogs_code"> <pre><div><span style="color: #008000">//</span><span style="color: #008000">程序11:输入三条线段的长度,判定它能否组成一个三角形。如果可以构成三角形,打印它所构成的三角形所构成的类型:等边/等腰/直角/任意三角形。</span><span style="color: #008000"></span><span style="color: #000000">#include </span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"></span><span style="color: #0000ff">int</span><span style="color: #000000"> fun(</span><span style="color: #0000ff">float</span><span style="color: #000000"> a, </span><span style="color: #0000ff">float</span><span style="color: #000000"> b, </span><span style="color: #0000ff">float</span><span style="color: #000000"> c){ </span><span style="color: #0000ff">int</span><span style="color: #000000"> n</span><span style="color: #000000">=</span><span style="color: #800080">0</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">n=0代表任意三角形 </span><span style="color: #008000">//</span><span style="color: #008000">n=1代表等边三角形 </span><span style="color: #008000">//</span><span style="color: #008000">n=2代表等腰三角形 </span><span style="color: #008000">//</span><span style="color: #008000">n=3代表直角三角形 </span><span style="color: #008000">//</span><span style="color: #008000">n=4代表不能构成三角形 </span><span style="color: #008000">//</span><span style="color: #008000">n=5代表等要直角三角形</span><span style="color: #008000"></span><span style="color: #000000"> </span><span style="color: #0000ff">if</span><span style="color: #000000"> (a</span><span style="color: #000000">+</span><span style="color: #000000">b</span><span style="color: #000000">></span><span style="color: #000000">c </span><span style="color: #000000">&&</span><span style="color: #000000"> abs(a</span><span style="color: #000000">-</span><span style="color: #000000">b)</span><span style="color: #000000"><</span><span style="color: #000000">c) { </span><span style="color: #0000ff">if</span><span style="color: #000000"> (a</span><span style="color: #000000">*</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">b</span><span style="color: #000000">*</span><span style="color: #000000">b</span><span style="color: #000000">==</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">c </span><span style="color: #000000">||</span><span style="color: #000000"> a</span><span style="color: #000000">*</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">c</span><span style="color: #000000">==</span><span style="color: #000000">b</span><span style="color: #000000">*</span><span style="color: #000000">b </span><span style="color: #000000">||</span><span style="color: #000000"> b</span><span style="color: #000000">*</span><span style="color: #000000">b</span><span style="color: #000000">+</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">c</span><span style="color: #000000">==</span><span style="color: #000000">a</span><span style="color: #000000">*</span><span style="color: #000000">a) { n</span><span style="color: #000000">=</span><span style="color: #800080">3</span><span style="color: #000000">; } </span><span style="color: #0000ff">if</span><span style="color: #000000"> (a</span><span style="color: #000000">==</span><span style="color: #000000">b </span><span style="color: #000000">||</span><span style="color: #000000"> a</span><span style="color: #000000">==</span><span style="color: #000000">c </span><span style="color: #000000">||</span><span style="color: #000000"> b</span><span style="color: #000000">==</span><span style="color: #000000">c) { n</span><span style="color: #000000">=</span><span style="color: #800080">2</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span><span style="color: #000000"> (a</span><span style="color: #000000">*</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">b</span><span style="color: #000000">*</span><span style="color: #000000">b</span><span style="color: #000000">==</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">c </span><span style="color: #000000">||</span><span style="color: #000000"> a</span><span style="color: #000000">*</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">c</span><span style="color: #000000">==</span><span style="color: #000000">b</span><span style="color: #000000">*</span><span style="color: #000000">b </span><span style="color: #000000">||</span><span style="color: #000000"> b</span><span style="color: #000000">*</span><span style="color: #000000">b</span><span style="color: #000000">+</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">c</span><span style="color: #000000">==</span><span style="color: #000000">a</span><span style="color: #000000">*</span><span style="color: #000000">a) { n</span><span style="color: #000000">=</span><span style="color: #800080">5</span><span style="color: #000000">; } } </span><span style="color: #0000ff">if</span><span style="color: #000000"> (a</span><span style="color: #000000">==</span><span style="color: #000000">b </span><span style="color: #000000">&&</span><span style="color: #000000"> a</span><span style="color: #000000">==</span><span style="color: #000000">c) { n</span><span style="color: #000000">=</span><span style="color: #800080">1</span><span style="color: #000000">; } } </span><span style="color: #0000ff">else</span><span style="color: #000000"> { n</span><span style="color: #000000">=</span><span style="color: #800080">4</span><span style="color: #000000">; } </span><span style="color: #0000ff">return</span><span style="color: #000000"> n;}</span><span style="color: #0000ff">int</span><span style="color: #000000"> main(){ </span><span style="color: #0000ff">float</span><span style="color: #000000"> a,b,c; printf(</span><span style="color: #800000">"</span><span style="color: #800000">输入数据\na=</span><span style="color: #800000">"</span><span style="color: #000000">); scanf(</span><span style="color: #800000">"</span><span style="color: #800000">%f</span><span style="color: #800000">"</span><span style="color: #000000">,</span><span style="color: #000000">&</span><span style="color: #000000">a); printf(</span><span style="color: #800000">"</span><span style="color: #800000">b=</span><span style="color: #800000">"</span><span style="color: #000000">); scanf(</span><span style="color: #800000">"</span><span style="color: #800000">%f</span><span style="color: #800000">"</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">b); printf(</span><span style="color: #800000">"</span><span style="color: #800000">c=</span><span style="color: #800000">"</span><span style="color: #000000">); scanf(</span><span style="color: #800000">"</span><span style="color: #800000">%f</span><span style="color: #800000">"</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">c); </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (fun(a,b,c)) { </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #800080">0</span><span style="color: #000000">: printf(</span><span style="color: #800000">"</span><span style="color: #800000">三角形为任意三角形\n</span><span style="color: #800000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">break</span><span style="color: #000000">; </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #800080">1</span><span style="color: #000000">: printf(</span><span style="color: #800000">"</span><span style="color: #800000">三角形为等边三角形\n</span><span style="color: #800000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">break</span><span style="color: #000000">; </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #800080">2</span><span style="color: #000000">: printf(</span><span style="color: #800000">"</span><span style="color: #800000">三角形为等腰三角形\n</span><span style="color: #800000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">break</span><span style="color: #000000">; </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #800080">3</span><span style="color: #000000">: printf(</span><span style="color: #800000">"</span><span style="color: #800000">三角形为直角三角形\n</span><span style="color: #800000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">break</span><span style="color: #000000">; </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #800080">4</span><span style="color: #000000">: printf(</span><span style="color: #800000">"</span><span style="color: #800000">不能构成三角形\n</span><span style="color: #800000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">break</span><span style="color: #000000">; </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #800080">5</span><span style="color: #000000">: printf(</span><span style="color: #800000">"</span><span style="color: #800000">三角形为等腰直角三角形\n</span><span style="color: #800000">"</span><span style="color: #000000">); </span><span style="color: #0000ff">break</span><span style="color: #000000">; } </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #800080">1</span><span style="color: #000000">;}</span></div></pre> </div> </span> <span style="color: #0000ff" color="#0000ff">测试结果:</span> <div class="cnblogs_code"> <pre><div><span style="color: #000000">[hanxi@hanxi</span><span style="color: #000000">-</span><span style="color: #000000">workstation Documents]$ .</span><span style="color: #000000">/</span><span style="color: #000000">a.</span><span style="color: #0000ff">out</span><span style="color: #000000">输入数据a</span><span style="color: #000000">=</span><span style="color: #800080">12</span><span style="color: #000000">b</span><span style="color: #000000">=</span><span style="color: #800080">12</span><span style="color: #000000">c</span><span style="color: #000000">=</span><span style="color: #800080">25</span><span style="color: #000000">不能构成三角形[hanxi@hanxi</span><span style="color: #000000">-</span><span style="color: #000000">workstation Documents]$ .</span><span style="color: #000000">/</span><span style="color: #000000">a.</span><span style="color: #0000ff">out</span><span style="color: #000000">输入数据a</span><span style="color: #000000">=</span><span style="color: #800080">12</span><span style="color: #000000">b</span><span style="color: #000000">=</span><span style="color: #800080">12</span><span style="color: #000000">c</span><span style="color: #000000">=</span><span style="color: #800080">23</span><span style="color: #000000">三角形为等腰三角形</span></div></pre> </div> </div>
试试其它关键字
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3