Syntax 1:
if(condition)
statement1;
else
statement2;
If the condition is true then statement1 will be executed, if the condition is false then statement2 will be executed.
/*read a number check the given number is even or odd and print it.*/
#include<stdio.h>
main()
{
int n,r;
clrscr();
printf("Enter a number");
scanf("%d",&n);
r=n/2;
if(r*2==n)
printf("%d is Even",n);
else
printf("%d is Odd",n);
getch();
}
syntax 2:
if(<condition>)
{
statement 1;
statement 2;
}
else
{
statement 3;
statement 4;
}
If the condition is true then statement1 and statement2 will be executed. If the condition is false then statement3 and statement4 will be executed.
/* read cost price, and selling price of an item findout the profit or loss. And findout how much it is. */
#include<stdio.h>
main()
{
float cp,sp,pl;
clrscr();
printf("Enter cost price, and selling price of an item");
scanf("%f%f",&cp,&sp);
if(cp<sp)
{
printf("Profit");
pl=sp-cp;
printf("= %.2f",pl);
}
else
{
printf("Loss");
pl=cp-sp;
printf("= %.2f",pl);
}
getch();
}
Syntax 3:
if(<condition>)
statement1;
else
statement2;
statement n;
If the condition is true then statement1 and statement n will be executed, if the condition is false then statement2 and statement n will be executed.
syntax 4:
if(<condition>)
{
statement 1;
statement 2;
}
else
{
statement 3;
statement 4;
}
statement n;
If the condition is true then statement1, statement2 and statement n will be executed. If the condition is false then statement3, statement4 and statement n will be executed.
/* read cost price, and selling price of an item findout the profit or loss. And findout how much it is. */
#include<stdio.h>
main()
{
float cp,sp,pl;
clrscr();
printf("Enter cost price, and selling price of an item");
scanf("%f%f",&cp,&sp);
if(cp<sp)
{
printf("Profit");
pl=sp-cp;
}
else
{
printf("Loss");
pl=cp-sp;
}
printf("= %.2f",pl);
getch();
}
if(condition)
statement1;
else
statement2;
If the condition is true then statement1 will be executed, if the condition is false then statement2 will be executed.
/*read a number check the given number is even or odd and print it.*/
#include<stdio.h>
main()
{
int n,r;
clrscr();
printf("Enter a number");
scanf("%d",&n);
r=n/2;
if(r*2==n)
printf("%d is Even",n);
else
printf("%d is Odd",n);
getch();
}
syntax 2:
if(<condition>)
{
statement 1;
statement 2;
}
else
{
statement 3;
statement 4;
}
If the condition is true then statement1 and statement2 will be executed. If the condition is false then statement3 and statement4 will be executed.
/* read cost price, and selling price of an item findout the profit or loss. And findout how much it is. */
#include<stdio.h>
main()
{
float cp,sp,pl;
clrscr();
printf("Enter cost price, and selling price of an item");
scanf("%f%f",&cp,&sp);
if(cp<sp)
{
printf("Profit");
pl=sp-cp;
printf("= %.2f",pl);
}
else
{
printf("Loss");
pl=cp-sp;
printf("= %.2f",pl);
}
getch();
}
Syntax 3:
if(<condition>)
statement1;
else
statement2;
statement n;
If the condition is true then statement1 and statement n will be executed, if the condition is false then statement2 and statement n will be executed.
syntax 4:
if(<condition>)
{
statement 1;
statement 2;
}
else
{
statement 3;
statement 4;
}
statement n;
If the condition is true then statement1, statement2 and statement n will be executed. If the condition is false then statement3, statement4 and statement n will be executed.
/* read cost price, and selling price of an item findout the profit or loss. And findout how much it is. */
#include<stdio.h>
main()
{
float cp,sp,pl;
clrscr();
printf("Enter cost price, and selling price of an item");
scanf("%f%f",&cp,&sp);
if(cp<sp)
{
printf("Profit");
pl=sp-cp;
}
else
{
printf("Loss");
pl=cp-sp;
}
printf("= %.2f",pl);
getch();
}
No comments:
Post a Comment