The decision control instruction can be implemented in C using:
The if statement :
Using keyword if, implement the decision control instruction.
Syntax :
if(condition is true)
{
//execute statement;
}
In that if the condition is true, then executed the statement, in contrast
if it is false then it is not executed.
for example:
void main()
{
int a,b;
printf("Enter two numbers for compare: \n");
scanf("%d%d",&a,&b);
if(a>b) //check the greater value(if(a greater than b))
{
printf("\n a is greater");
}
if(a<b) //check the greater value(if (a less than b))
{
printf("\n b is greater");
}
if(a==b) //check the value(if (a equal to b))
{
printf("\n both are equal");
}
getch();
}
Output of above example:
Enter two numbers for compare:
10 5 // a=10 and b=5
a is greater
if a=5 and b=10
b is greater
- The if statement
- The if-else statement
- The conditional operator
The if statement :
Using keyword if, implement the decision control instruction.
Syntax :
if(condition is true)
{
//execute statement;
}
In that if the condition is true, then executed the statement, in contrast
if it is false then it is not executed.
for example:
void main()
{
int a,b;
printf("Enter two numbers for compare: \n");
scanf("%d%d",&a,&b);
if(a>b) //check the greater value(if(a greater than b))
{
printf("\n a is greater");
}
if(a<b) //check the greater value(if (a less than b))
{
printf("\n b is greater");
}
if(a==b) //check the value(if (a equal to b))
{
printf("\n both are equal");
}
getch();
}
Output of above example:
Enter two numbers for compare:
10 5 // a=10 and b=5
a is greater
if a=5 and b=10
b is greater
0 comments:
Post a Comment