simple if


simple if statement

The general form of  simple if statement is:
            if(Test Condition)
            {
                        Statement-1;
            }
            Next-statement;

Next-statement
 
                                                  


The statement is any valid C’ language statement and the condition is any valid C’ language expression, frequently logical operators are used in the condition statement. The condition part should not end with a semicolon, since the condition and statement should be put together as a single statement. The command says if the condition is true then perform the following statement or If the condition is fake the computer skips the statement and moves on to the next instruction in the program. The The statement-x can contain one or more statements. Braces are required only if we are having more than one statement. Here else part is ommited.




Eg:-  
if(category==sports)
{
            marks=marks+bonus_marks;
}
printf(“%d”,marks);  

            if(a>=60&&a<70)
                        printf(“First Class”);
           
Sample Program to find the absolute value of given number.

#include<stdio.h>
#include<conio.h>
void main ()
{
            int n;
            printf(“Enter n: “);
            scanf(“%d”,&n);
            if(n<0)
               n=-n;
            printf(“The Absolute value: %d”,n);
}

Output:-

Enter n: -8
The Absolute value: 8



No comments:

Post a Comment