if else in C language by R4R Team

Syntax-
if(condition)
{
}
else
{
}

-If the condition is true then if part is execute otherwise else part is execute.

Example-

if(2==8)
{
printf("If part");
}
else
{
printf("Else part");
}

//Else part


program-

#include< stdio.h>
int main()
{
int a;
printf("Enter Number\n");
scanf("%d",&a);
if(a==1)
{
printf("If part");
}
else
{
printf("Else part");
}
}


output-

Enter Number
5
Else part

Enter Number
1
If part


-In this program, we take a input of the number and then check that number is 1 or not by a==1
-if a==1 then it execute the if statement otherwise execute else part.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!