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;
}
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 08/16/07



{ 17 comments… read them below or add one }
I need more if else program.i have simple problem.i don’t know your wbsite is active or not.next time i give a problem please solve it.
can you convert this to java program?
I just study programming .
hello all..exiting ang programming nuh?haha
how to analyze the problem to make c program?tnx
hi i am a n IT student. i just want to ask if you could pls give me some simple problems regarding if else , if else if else, and i/o. and also those more complicated ones. thanks.
Super Example For If Statement
i’m excited to try this program
i need to create program right now for my project …………….help me …………………hehehe using IF ELSE STATEMENT
Give me another example of IF ELSE STATEMENT
can you help me to write this home work in C programs
*wirte the programsin C about if else
*the program should ask the user to enter the total marks out of 100, and then display the letter grade on the screen
*Grade Rules:
75 and above=”A”grade
60-74=”B”grade
50-59=”c”grade
40-49=”D”grade
Below 40=”Fail”
thanks .
please send it to my Email bayan321@live.com
i need some help guys
i am making a function oriented program and i used if else statement, i know that my statement is right but there is only 1 error and it says misplaced else…..
how can i fix that?
pls help me….
plss notify me on my email
thanks
can you give more examples :-)
Thanks I love you!!
pls. give me a program example of official receipt of sm using if else statement pls. we need it badly…pls…thanx
why can’t I place another “if statement” inside and “if statement”?