if(x>y) cout<<x<<endl;
if (x>y) cout<<x; else cout<<y;
if(表达式1) 语句1 else if(表达式2) 语句2 else if(表达式3) 语句3 … else if(表达式m) 语句m else 语句n
if (number>500) cost=0.15; else if(number>300) cost=0.10; else if(number>100) cost=0.075; else if(number>50) cost=0.05; else cost=0;
#include <iostream>
#include <cmath> //使用数学函数时要包含头文件cmath
#include <iomanip> //使用I/O流控制符要包含头文件iomanip
using namespace std;
int main( )
{
double a,b,c;
cout<<"please enter a,b,c:";
cin>>a>>b>>c;
if (a+b>c && b+c>a && c+a>b)
{ //复合语句开始
double s,area;//在复合语句内定义变量
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<setiosflags(ios::fixed)<<setprecision(4); //指定输出的数包含4位小数
cout<<"area="<<area<<endl; //在复合语句内输出局部变量的值
} //复合语句结束
else cout<<"it is not a trilateral!"<<endl;
return 0;
}
please enter a, b, c:2.45 3.67 4.89↙ area=4.3565
if( ) if( )语句1 else 语句2 else if( )语句3 else 语句4
if( ) if( )语句1 else if( )语句2 else 语句3
if( )
{
if ( ) 语句1
} //这个语句是上一行if语句的内嵌if
else 语句2//本行与第一个if配对
if (a>b) max=a; else max=b;
max=(a>b)?a:b;
表达式1 ? 表达式2 : 表达式3;
x ? 'a': 'b';
#include <iostream>
using namespace std;
int main( )
{
char ch;
cin>>ch;
ch=(ch>='A' && ch<='Z')?(ch+32):ch; //判别ch是否大写字母,是则转换
cout<<ch<<endl;
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有