Hello friends how are you, today in this blog i will teach you what is if statement, syntax of if , how if statement works and many programs using if statement in a very simple way.
Let's start
👉Syntax
1.If the condition is true its body execute otherwise does not execute.
2.In the case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition true
👉Example 1
#include<stdio.h>
int main()
{
//Assigning value to the variable
int x=50,y=20;
//checking the condition
if(x>y)
{
printf("x is greater than y");
}
}
### Output ###
x is greater than y
👉Example 2
#include<stdio.h>
int main()
{
//Assigning value to the variable
int x=50,y=20;
//checking the condition
if(x<y)
{
printf("x is greater than y");
}
}
/*
### Output ###
condition is false so there is no output
*/
👉Example 3
#include<stdio.h>
int main()
{
if(8)
{
printf("Hello");
}
}
/*
### Output ###
Hello
*/
👉Example 4
#include<stdio.h>
int main()
{
if(0)
{
printf("Hello");
}
}
/*
### Output ###
*/
👉Example 5
#include<stdio.h>
int main()
{
if(8,9,6,0,0,7,8)
{
printf("Hello");
}
}
/*
### Output ###
Hello
*/
👉Program: Greatest Value three numbers
#include<stdio.h>
int main()
{
int no1,no2,no3;
printf("Enter number1:");
scanf("%d",&no1);
printf("Enter number2:");
scanf("%d",&no2);
printf("Enter number3:");
scanf("%d",&no3);
if(no1>no2&&no1>no3)
printf("%d is greaest value",no1);
if(no2>no1&&no2>no3)
printf("%d is greaest value",no2);
if(no3>no2&&no3>no1)
printf("%d is greaest value",no3);
}
/*
### Output ###
Enter number1:84
Enter number2:95
Enter number3:67
95 is greatest value
*/
Request:-If you found this post helpful then let me know by
your comment and share it with your friend.
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.
If you have not subscribed my website then please subscribe my website.
Try to learn something new and teach something new to other.
Thanks.
0 Comments