If else statement in C Program

by Vivek Gite · 17 comments

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:

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!

{ 17 comments… read them below or add one }

1 ferdinand v. baguingay 12.10.08 at 3:22 am
#include
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;
}
2 nazmul 01.27.09 at 9:42 am

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.

3 aldrin 03.22.09 at 1:34 pm

can you convert this to java program?

4 saviye.saviyola 04.21.09 at 4:01 am

I just study programming .

5 alyssa mae cruz 07.06.09 at 8:01 am

hello all..exiting ang programming nuh?haha

6 markjasonarceo 09.21.09 at 9:45 am

how to analyze the problem to make c program?tnx

7 carrys 09.24.09 at 3:41 am

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.

8 Pooja Sree 12.03.09 at 5:15 am

Super Example For If Statement

9 allen joyce 12.15.09 at 5:55 am

i’m excited to try this program

10 allen joyce 12.15.09 at 5:57 am

i need to create program right now for my project …………….help me …………………hehehe using IF ELSE STATEMENT

11 allen joyce 12.15.09 at 5:58 am

Give me another example of IF ELSE STATEMENT

12 bayan 12.23.09 at 1:27 pm

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

13 emxif 01.22.10 at 6:14 am

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

14 Glenn 02.03.10 at 2:26 am

can you give more examples :-)

15 Levi 02.18.10 at 1:21 am

Thanks I love you!!

16 mabel 03.06.10 at 2:54 pm

pls. give me a program example of official receipt of sm using if else statement pls. we need it badly…pls…thanx

17 Darren 03.09.10 at 11:47 pm

why can’t I place another “if statement” inside and “if statement”?

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All