如果在C程序中使用else语句
时间:2020-01-09 10:40:51 来源:igfitidea点击:
问题描述:您能举Linux或TC下C程序中if else语句的例子吗?
答:
C遵循if..else的通用语法。
您可以使用任何兼容的GNU Linux gcc或UNIX或较旧的TC。
if..else语法
常规if..else语法如下:
if ( condition ) {
expr_set1;
}
else {
expr_set2;
}
如果给定条件为TRUE,则将执行expr_set1。
如果给定条件为FALSE(不是TRUE),则将执行expr_set2。
if..else示例
以下示例将从给定的输入中找出大量数字:
#include<stdio.h>
int main(){
int x,y;
printf("Enter value for x :");
scanf("%d",&x);
printf("Enter value for y :");
scanf("%d",&y);
if ( x > y ){
printf("X is large number - %d\n",x);
}
else{
printf("Y is large number - %d\n",y);
}
return 0;
}

