Home » , , » Decision Control Statement In C Programming - " Ifelse and elseif "

Decision Control Statement In C Programming - " Ifelse and elseif "

Written By Unknown on Wednesday, October 9, 2013 | 10:36 AM

If Else :
We can use “else” with “if” but it is up to us that will we use or not.The way to use else with is as below:

If(expression)
        statement  1;
else
        statement 2;


If the value of “if” expression become true than statement 1 will be execute otherwise statement 2 will execute.

Watch the program carefully :
                                                                    #include<stdio.h>
                                                                    #include<conio.h>
                                                                     main()
                                                                     {
                                                                     int numb;
                                                                     printf("Enter How Much Money do You Have? : ");
                                                                     scanf("%d",&numb);
                                                                     if(numb>50)
                                                                     printf("You are rich");
                                                                     else
                                                                     printf("You are poor");
                                                                     getch();
                                                                     }

Program Analysis:
Here two simple statement and condition are working that if the entered  number  become grater than 50,First statement will excuete otherwise if the number remain under 50 second statement will be published.



Elseif:
We can create “if else if” chain through else if in C Program.The structure is as following:
                                                          If(expression 1)
                                                                   Statement 1;
                                                          Else
                                                                  If(expression 2)
                                                                   Statement 2;

                                                           Else

                                                                   Statement3; 
Share this article :

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Learn Programming - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger| Distributed by Rocking Templates