If else statement in C Program
Q. Can you give me example for If else statement in C Program under Linux or TC?
A. C follows universal syntax for if..else. You can use any complier GNU Linux gcc or UNIX or old good TC.
if..else syntax
General if..else syntax is as follows:
if ( condition ) {
expr_set1;
}
else {
expr_set2;
}
If given condition is TRUE, expr_set1 will get executed.
If given condition is FALSE (not TRUE), expr_set2 will get executed.
if..else example
Following example will find out large number from given input:
#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;
}
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- How do I enable SQL *Plus Up and down arrow keys?
- PHP Howto Read IP address of remote computer/browser
- Create a mysql database, tables and insert data
- How you can run a c program in Linux?
- Howto see output of C program in Linux or UNIX
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: c_program, gnu_linux, if_else_syntax, linux_gcc, tc



Recent Comments
Today ~ 1 Comment
Today ~ 3 Comments
Today ~ 57 Comments
Yesterday ~ 9 Comments
Yesterday ~ 7 Comments