Programs of Decision making statement
For understanding these programs you have to first clear the concept of decision making statements.
P1. Program to find the greatest number among the three no.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, c, gt;
printf(“ enter the
three numbers “);
scanf(“ %d %d %d “,
&a, &b, &c );
if(a>b &&
a>c)
gt= a;
else if (b>c)
gt= b;
else
gt= c;
printf(“ greatest
number = %d “, gt);
getch();
P2. Program to input marks of five subject after that find total marks, percentage marks and remarks according to given condition.
I.
percentage >= 90 remarks= ‘excellent’
II.
percentage >=75 remarks=’very good’
III.
percentage < 75 an percentage >= 60 ‘good’
IV.
otherwise
remarks =’poor’
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, c, d, e,
per, T;
printf(“ enter the
marks of five subject” );
scanf( “%d %d %d %d
%d “, &a, &b ,&c ,&d, &e );
T= a+b+c+d+e;
per= T/5;
if(per >= 90)
printf(“ Remarks =
\”excellent\” );
else if (per > 75)
printf( “ Remarks =
\”very good\”);
else if( per >
60)
printf( “ Remarks
=\ “good\”);
else
printf( “ Remarks
= \”poor\” );
printf(“ Total marks = %d”, T);
printf(“ \n percentage marks = %d “, per);
getch();
}
Program to print marksheet |
P3. Programs of basic salary of an employee after that find growth salary for given extra allowance on basic salary .
Basic salary
|
HRA
|
DA
|
TA
|
MA
|
>= 20000
|
40%
|
90%
|
40%
|
10%
|
< 20000
|
30%
|
70%
|
30%
|
8%
|
< 15000
|
20%
|
60%
|
20%
|
5%
|
< 10000
|
15%
|
50%
|
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float bs, hra, da,
ta, ma, gs;
printf(“ enter the
basic salary of the employee “);
scanf( “ %f”
,&bs );
if( bs >= 20000)
{
hra= (bs * 40 )/
100;
da = ( bs *90 )/
100;
ta= ( bs * 40 )/
100;
ma= (bs * 10) /100;
gs = bs+ hra + da +
ta + ma ;
}
else if (bs <
20000 && bs >= 15000)
{
hra= (bs * 30) /
100;
da = (bs * 70 )/
100;
ta = (bs * 30
)/100;
ma = (bs * 8 )/100;
gs= bs + hra + da +
ta + ma;
}
else if ( bs < 15000 && bs >= 10000)
{
hra = (bs * 20 )/
100;
da = (bs * 60 )/
100;
ta = ( bs * 20 )/
100;
ma =( bs * 5 )/
100;
gs = bs + hra + da
+ ta + ma ;
}
else
{
hra = ( bs * 5 )
/100;
da = ( bs * 50 )/
100;
gs = bs + hra + da ;
}
printf( “ basic salary = %f \n hra = %f \n da= %f \n ta= %f
\n
ma=
%f\n gs= %f”, bs, hra, da, ta, ma, gs );
getch();
Program to print salary slip 2 |
P4. Program to input any character after that check character is lower alphabet , upper alphabet, digit or special character .
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
printf(“ enter any character “);
scanf(“%c”,
&ch);
if( ch >= “A”
&& ch <= “Z”)
printf(“ Upper alphabet “);
else if( ch >= “a”
&& ch <= “z”)
printf(“ lower
alphabet “ );
else if ( ch >= “0”
&& ch <= “9”)
printf( “ digit” );
else
printf( “ special
character “);
getch();
P5. Program to input any year after that check year is leap or not using nested if.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
printf(“enter any
year “ );
scanf(“ %d “, &a
);
if ( a% 100! = 0)
{
if( a% 4 == 0)
printf( “
leap year “);
}
else if( a % 400 == 0
)
printf( “ leap year “);
else
printf( “ not
leap year “);
getch();
}
}
Program to check leap year |
P6. Program to input three nos. after that find smallest no. using nested if.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c,st;
clrscr();
printf( “ enter the
three nos. “);
scanf( “ %d %d %d “,
&a, &b, &c);
if( a <b)
{
if( a < c)
st=a;
else
st=c;
}
else if(b<c)
{
st= b;
else
st=c;
}
printf(“ smallest no.= %d”, st);
getch();
No comments:
Post a Comment