If else statement in C Program

Q. Can you give me example for If else statement in C Program under Linux or TC?

Advertisement

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;
}

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

337 comments… add one
  • elywin mutetwa Oct 5, 2017 @ 13:57

    Write a program that performs an arithmetic sequence summation (arithmetic series). The
    program should accept the following values from the user

  • shahmeer khan Nov 18, 2017 @ 19:31

    A C++ program is required to calculate the bill for an item purchased from a store. The sales person shall be asked to enter item name, item category, unit price, quantity. The printed bill should contain the item name, quantity purchased, price of the item, sale tax amount and total amount to be paid by the customer.
    The store have four different categories of items on sale. A sale tax is deducted from the customer based on the category of the item purchased. There is no sale tax on category 1 items, 3% on category 2 items, 5% of category 3 items, and 7% of category 4 items.

  • afiq Aug 27, 2020 @ 14:53

    1690124865666b6279abbc5_000001

    WHAT IS WRONG IN THIS PROGRAMING?

  • Muzamil Iqbal Oct 31, 2020 @ 11:59

    Very good Post

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.