IF ELSE IN C LANGUAGE

                IF ELSE FOR C LANGUAGE

 Hello Guys  welcome to my blog coding Master mind. How to work if else in c language this statement is very important of c language and c++ that works most wonderful programming language and use game development and software development. Hey guys let's start

my self Tarun Ghritalahare your Blog host and writers .


                                 IF

The syntax of an 'if' statement in C programming language is − if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } If the Boolean expression evaluates to true, then the block of code inside the 'if' statement will be executed.

                                 CODE

#include <stdio.h>

 void main()

 { int a; 

printf("Enter Number : ");

 scanf("%d", &a);

 if (a%2 == 0) 

printf("You entered an even number"); 

}

                            OUTPUT




                                 ELSE





What Does Else Statement Mean?


In programming languages, an else statement is an alternative statement that is executed if the result of a previous test condition evaluates to false


Techopedia Explains Else Statement


The syntax of the else statement is very similar between different high-level programming languages like PHP, Java, C/C++/C#, Object Pascal, etc. Even early programming languages such as Basic and Fortran have the ability to process an else statement as part of a general syntactical approach to linear programming.


The else statement is an optional statement that is normally used in an "if-else" or "if-else if-else" construction. The way the else statement works is that, if the condition associated with either the "if" or the "else if" control structure is false, program control automatically goes to the else statement, if present.


For example,

If X is true Then

Do Something

Else

Do Another Thing

End If

Or

If X = 1 Then

Do Statement 1

Else If X = 2 Then

Do Statement 2

Else

Do Another Thing

End If

Note that, unlike the "if" and "else if" control structure, there is no test condition associated with the else statement.


In Object Pascal, the else statement may also be used in a "case" statement and it serves the same purpose as the "default statement" in the C family of languages such as C/C++, C# and Java.

 

                             CODE


#include <stdio.h>

int main() {

    int number;


    printf("Enter an integer: ");

    scanf("%d", &number);


    // true if number is less than 0

    if (number < 0) {

        printf("You entered %d.\n", number);

    }


    printf("The if statement is easy.");


    return 0;

}

                                     OUTPUT

Enter an integer: -2 You entered -2. The if statement is easy.







Post a Comment

0 Comments