Академический Документы
Профессиональный Документы
Культура Документы
If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA =
90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA =
Rs. 500 and DA = 98% of basic salary. If the employee's salary is input through
the keyboard write a program to find his gross salary.
/* Calculation of gross salary */
#include <stdio.h>
#include <math.h>
#include <conio.h>
Void main( )
{
float bs, gs, da, hra ;
printf ( "Enter basic salary " ) ;
scanf ( "%f", &bs ) ;
if ( bs < 1500 )
{
hra = bs * 10 / 100 ;
da = bs * 90 / 100 ;
}
else
{
hra = 500 ;
da = bs * 98 / 100 ;
}
gs = bs + hra + da ;
printf ( "gross salary = Rs. %f", gs ) ;
}
If Three sides of a triangle are given, then calculate the area of a triangle.
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
float a,b,c,area,s,x;
clrscr();
L : printf ("\n Give Three sides of a triangle : ");
scanf ("%f %f %f", &a,&b,&c);
printf("\n The sides are %f %f %f", a,b,c);
if((a+b)<=c || (a+c)<=b || (b+c)<=a)
{
printf ("\n Triangle can't be formed");
printf ("\n Give appropriate sides that a triangle can be formed");
goto L;
}
else
{
s=(a+b+c)/2.0;
}
getch();
}
x=s*(s-a)*(s-b)*(s-c);
area =pow(x,0.5);
printf("\n The area of the triangle : %f square unit", area);
NOTE :
<stdio.h>
<conio.h>
<stdlib.h>
<ctype.h>
void main()
{
clrscr();
char x;
printf ("\n give a character : ");
x=getchar();
if (isupper(x))
printf ("\n %c is in upper case letter ",x);
else
printf ("\n %c is not in upper case letter ",x);
getch();
}
Write a program to accept a character and that whether it is in upper case or in
lower case without using isupper().
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
clrscr();
char x;
printf ("\n give a character : ");
x=getchar();
if (x>='A' && x<='Z')
printf ("\n %c is in upper case letter ",x);
else
printf ("\n %c is not in upper case letter ",x);
getch();
clrscr();
char x;
printf ("\n give a character : ");
x=getchar();
if (upper(x))
printf ("\n %c is in upper case letter ",x);
else
printf ("\n %c is not in upper case letter ",x);
getch();
int upper(char c)
{
Write a program to accept a character and that whether it is in lower case or not
using user defined function.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int lower(char);
void main()
{
clrscr();
char x;
printf ("\n give a character : ");
x=getchar();
if (lower(x))
else
}
Write a program to accept a character and test whether it is digit or not using user
defined function.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int digit(char);
void main()
{
clrscr();
char x;
printf ("\n give a character : ");
x=getchar();
if (digit(x))
printf ("\n %c is digit ",x);
else
printf ("\n %c is not a digit ",x);
getch();
}
int digit(char c)
{
if (c>='0' && c<='9')
return(1);
return(0);
}
Write a program to accept a character and test whether it is character or not using
user defined function.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int alpha(char);
void main()
{
clrscr();
char x;
printf ("\n give a character : ");
x=getchar();
if (alpha(x))
printf ("\n %c is alphabet ",x);
else
printf ("\n %c is not a alphabet ",x);
getch();
}
int alphabet(char c)
{
}
Write a program to find the number of combinations that can be taking r number
of values from n number of integers using the relation : Number of combinations
= n!/r!(n-r)! (using function)
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
clrscr();
void comb(int x,int y);
int n,r;
printf("\n enter the value of n and r :");
scanf("%d %d",&n,&r);
if(n<=0 || r<=0 || n<=r)
{
printf("\n absured values entered, can't be done");
exit(0);
}
else
comb(n,r);
}
void comb(int x,int y)
{
long long int f1,f2,f3,i,f;
f1=f2=f3=1;
for(i=1;i<=x;i++)
f1*=i;
for(i=1;i<=y;i++)
f2*=i;
for(i=1;i<=x-y;i++)
f3*=i;
f=f1/(f2*f3);
printf("\n number of combinations = %d",f);
getch();
}
Write a program to find the largest and the smallest from the given three integers.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
clrscr();
int a,b,c,max,min;
printf("\n enter any three integers :");
scanf("%d%d%d",&a,&b,&c);
if (a>b)
{
if(a>c)
max=a;
else
max=c;
}
else
{
if (b>c)
max=b;
else
max=c;
}
if(a<b)
{
if(a<c)
min=a;
else
min=c;
}
else
{
if (b<c)
min=b;
else
min=c;
}
printf("\n maximum = %d", max);
printf("\n minimum = %d", min);
getch();
}
The marks obtained by a student in 5 different subjects are input through the
keyboard. The student gets a division as per the following rules:
Percentage
Percentage
Percentage
Percentage
insured" ) ;
not insured" ) ;
insured" ) ;
not insured" ) ;
}
/* Insurance of driver - using logical operators */
main( )
{
char sex, ms ;
int age ;
printf ( "Enter age, sex, marital status " ) ;
scanf ( "%d %c %c" &age, &sex, &ms ) ;
if ((ms == 'M') || (ms == 'U' && sex == 'M' && age > 30) ||
(ms == 'U' && sex == 'F' && age > 25))
printf ("Driver is insured") ;
else
printf ("Driver is not insured") ;
}
An employee can apply for a loan at the beginning of every six months, but he will
be sanctioned the amount according to the following company rules :
Rule 1 : An employee cannot enjoy more than two loans at any point of time.
Rule 2 : Max permissible total loan is limited and depends upon the category of the
employee.
#include <stdio.h>
#include <conio.h>
#define MAXLOAN 50000
void main()
{
clrscr();
long int loan1,loan2,loan3,sancloan,sum23;
printf(Enter the values of previous two loans :\n);
scanf(%ld %ld, &loan1,&loan2);
printf(Enter the value of new loan :\n);
scanf(%ld, &loan3);
sum23=loan2+loan3;
sancloan = (loan1>0)? 0 : ((sum23>MAXLOAN)? MAXLOAN-loan2 : loan3);
printf(\n \n);
printf(Previous loans pending :\n%ld %ld\n, loan1, loan2);
printf(loan requested : %ld\n, loan3);
printf(loan sanctioned : %ld\n, sancloan);
getch();
}
In an office there are three grades of employees, namely grade 1, 2 and 3.
Calculate the bonus obtained by them as per the following rules :
For Grade 1 : Bonus = 10% of pay
For Grade 2 : Bonus = 12% of pay, subject to a maximum of Rs. 2500
For Grade 3 :
Pay
Bonus
Upto Rs. 5000
5% of pay
Above Rs. 5000 but upto Rs. 8000
7% of pay
Above Rs. 8000
10% of pay
#include <stdio.h>
#include <conio.h>
void main()
{
int grade;
float pay, bonus;
printf( Enter your pay please in Rs. : );
scanf(%f,&pay);
fflush(stdin);
printf( \nEnter your grade please (1/2/3) : );
scanf(%d,&grade);
switch (grade)
{
case 1 :
bonus=0.1*pay;
break;
case 2 :
bonus=0.05*pay;
if (bonus>2500)
bonus=2500;
break;
case 3 :
if (pay<=5000)
bonus=0.05*pay;
if (pay>5000 && pay<=8000)
bonus=0.07*pay;
if (pay>8000)
bonus=0.1*pay;
break;
default :
printf(\nAbsurd Grade Entered);
}
printf(\nYour Bonus Amount Rs = %f, bonus);
getch();
In a hotel there are three floors and in each floor there are four types of room
available having different room charges given below. Write a program to print the
room charges by entering the floor number and class of room. The room charges
are as follows :
In floor 1
A Class = Rs. 750
B Class = Rs. 600
C Class = Rs. 500
In floor 2
A Class = Rs. 1200
B Class = Rs. 1000
M Class = Rs. 300
In floor 3
1 Class = Rs. 2500
2 Class = Rs. 1800
A Class = Rs. 1200
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
clrscr();
int floor, charge;
char c1;
cout<<"Enter the Floor Number (1/2/3) : ";
cin>>floor;
cout<<" \nEnter Class of Room (A/B/C/M/1/2) : ";
cin>>c1;
switch (floor)
case 1 :
switch(c1)
{
case 'A' :
case 'a' :
charge=750;
break;
case 'B' :
case 'b' :
charge=600;
break;
case 'C' :
case 'c' :
charge=500;
break;
default :
cout<<"\nAbsurd Class of Room";
getch();
exit(0);
}
break;
case 2 :
switch(c1)
{
case 'A' :
case 'a' :
charge=1200;
break;
case 'B' :
case 'b' :
charge=1000;
break;
case 'M' :
case 'm' :
charge=300;
break;
default :
cout<<"\nAbsurd Class of Room";
getch();
exit(0);
}
break;
case 3 :
switch(c1)
{
case '1' :
charge=2500;
break;
case '2' :
charge=1800;
break;
case 'A' :
}
break;
case'a' :
charge=1200;
break;
default :
cout<<"\nAbsurd Class of Room";
getch();
exit(0);
}
cout<<"\nRoom Charges is Rs = "<<charge;
getch();
}