Q-1: Mr. Aggarwal is an employee of a Private Firm. His Basic salary is Rs. 5500/-(suppose) . Now the dearness allowance is 74% of his basic salary and house rent allowance is 15% of basic salary. Write a program to calculate his gross salary.
#include<stdio.h>
#include<conio.h>
void main()
{
float gs,da,bs,hr;
clrscr();
printf("\n\t\tENTER THE BASIC SALARY OF AN EMPLOYEE:");
scanf("%f",&bs);
da=(bs*74)/100;
hr=(bs*15)/100;
gs=bs+hr+da;
printf("\n\t\tTHE GROSS SALARY:%f",gs);
getch();
}
Q-2: The length and breadth of a rectangle and radius of a circle are input through key board. Write a program to calculate the area and perimeter of the rectangle and the area and the circumference of the circle.
#include<stdio.h>
#include<conio.h>
void main()
{
float len,bre,aor,aoc,por,coc,rad;
clrscr();
printf("\n\t\tENTER THE LENGTH OF THE RECTANLE:");
scanf("%f",&len);
printf("\n\t\tENTER THE BREADTH OF THE RECTANLE:");
scanf("%f",&bre);
printf("\n\t\tENTER THE RADIUS OF THE CIRCLE:");
scanf("%f",&rad);
aor=len*bre;
por=2*(len+bre);
aoc=3.14*rad*rad;
coc=3.14*2*rad;
printf("\n\t\tTHE AREA OF RECTANGLE:%f",aor);
printf("\n\n\t\tTHE PERIMETER OF RECTANGLE:%f",por);
printf("\n\n\t\tTHE AREA OF CIRCLE:%f",aoc);
printf("\n\n\t\tTHE CIRCUMFERENCE OF CIRCLE:%f",coc);
getch();
}
Q-3: Temperatures of a city in Fahrenheit degree are input through a keyboard. Write a prgram to convert the temperature into centigrade degrees.
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
clrscr();
printf("\n\t\tENTER THE TEMPRATURE IN FARENHEIT:");
scanf("%f",&f);
c=5*(f-32)/9;
printf("\n\t\tTHE TEMPRATURE IS IN CELSIUS:%f",c);
getch();
}
Q-4-a: Write a program to swap two numbers by using third variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("\n\t\tENTER ANY NUMBER FOR a:");
scanf("%d",&a);
printf("\n\t\tENTER ANY NUMBER FOR b:");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("\n\t\tTHE SWAPPING OF a=%d AND b=%d",a,b);
getch();
}
Q-4-a: Write a program to swap two numbers without using third variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\n\t\tENTER ANY NUMBER FOR a:");
scanf("%d",&a);
printf("\n\t\tENTER ANY NUMBER FOR b:");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("\n\t\tTHE SWAPPING OF a=%d AND b=%d",a,b);
getch();
}
Q-5: Write a program to find area of a triangle: Area of triangle = sqrt[s(s-a)(s-b)(s-c)] where a,b, and c are three sides of the triangle and s=a+b+c/2.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double s,a,b,c,aot;
clrscr();
printf("### Area Of Triangle ###\n");
printf("\nENTER THE VALUE FOR a:");
scanf("%lf",&a);
printf("\nENTER THE VALUE FOR b:");
scanf("%lf",&b);
printf("\nENTER THE VALUE FOR c:");
scanf("%lf",&c);
s=(a+b+c)/2;
printf("\nS=%lf",s);
aot=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nAREA OF TRIANGLE:%lf",aot);
getch();
}
Q-6: Write a program to calculate and print electricity bill for consumers, given the following information: service number, previous meter reading, and current reading.
#include<stdio.h>
#include<conio.h>
void main()
{
int pre,c,sn;
float bill_amt,pre_amt,unit;
clrscr();
printf("\t\tWelcome To Kolkata Electricity Board\n");
printf("\n\n ENTER SERVICE NUMBER:");
scanf("%d",sn);
printf("\nENTER THE PREVIOUS MONTH READING UNIT USED:");
scanf("%d",&pre);
printf("\nENTER THE CURRENT MONTH READING UNIT USED:");
scanf("%d",&c);
pre_amt=pre*2.5;
bill_amt=c*2.5;
printf("\nCustomer With SERVICE NUMBER:%d",sn);
printf("\n\t\tCustomer's Previous Bill Amount:%f",pre_amt);
printf("\n\t\tCustomer's Current Bill Amount:%f",bill_amt);
getch();
}
What happens when I enter characters as salary and not numbers ? - Applies to Q1 -Q3 and Q5 - Q7. For Q4 what happens when the number I enter add upto greater than size of int ? Sure the code blows up ;-)
ReplyDelete