Friday, 7 August 2015

if statements in c Language Syntax and E.g

if statement
It is the most simple form of the branching statements.It takes an expression in parenthesis and an statement or block of statements. if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.

(1) if statement
(2) if else statement

Syntax of if statement:
(1)
if(Condition's)                                 
statement 1
statement 2
....
.....
........
statement n
E.g.1
main()
{
int a=9;
if(a>90)
printf("Hello");
printf("Hi");
printf(" Unique Programming");
}
Output:
Hi Unique Programming
E.g.2
main()
{
int a=9;
if(a<90)
printf("Hello");
printf("Hi");
printf(" Unique Programming");
}
Output:
Hello Hi Unique Programming

(2)
if(Condition's)
{
statement's
}
statement 2
....
.....


........
statement n

E.g.1
main()
{
int a=9;
if(a>90)
{
printf("Hello");
printf("Students");
}
printf("Hi");
printf(" Unique Programming");
}
Output:
Hi Unique Programming

E.g.2
main()
{
int a=9;
if(a<90)
{
printf("Hello");
printf(" Students");
}
printf("Hi");
printf(" Unique Programming");
}
Output:
Hello Students Hi Unique Programming

Syntax of If else Statement:

(1)
if(Condition's)                                 
statement 1
else
statement 2
....
.....
........
statement n
E.g.1
main()
{
int a=9;
if(a>90)
printf("Hello");
else
printf("Hi");
printf(" Unique Programming");
}
Output:
Hi Unique Programming
E.g.2
main()
{
int a=9;
if(a<90)
printf("Hello");
else
printf("Hi");
printf(" Unique Programming");
}
Output:
Hello Unique Programming

(2)
if(Condition's)
{
statement's
}
else
{
statement 's
}....
.....


........
statement n

E.g.1
main()
{
int a=9;
if(a>90)
{
printf("Hello");
printf("Students");
}
else
{
printf("Hi");
printf(" Unique Programming");
}
}
Output:
Hi Unique Programming

E.g.2
main()
{
int a=9;
if(a<90)
{
printf("Hello");
printf(" Students");
}
else
{
printf("Hi");
printf(" Unique Programming");
}
}
Output:
Hello Students


No comments:

Post a Comment