Showing posts with label Chapter-01 Getting Started. Show all posts
Showing posts with label Chapter-01 Getting Started. Show all posts

Saturday, 24 March 2012

The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.


The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.  
#include<stdio.h>
#include<conio.h>
void main(void)
{
int km;
long int meters, feet, inches, centimeters;
clrscr();
printf("Please enter distance between two cities: ");
scanf("%d", &km);
meters=km*1000;
feet=meters*3;
inches=feet*12;
centimeters=meters*100;
printf("\n\nMeters=%ld", meters);
printf("\nFeet=%ld", feet);
printf("\nInches=%ld", inches);
printf("\ncentimeters=%ld", centimeters);
getch();
}


Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

Q: Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.


#include<stdio.h>
#include<conio.h>
void main(void)
{
int bas_sal;
float med_al, h_rent, gross_sal;
clrscr();
printf("Please enter Ramesh basic Salary : ");
scanf("%d", &bas_sal);
med_al = 40*bas_sal/100;
h_rent = 20*bas_sal/100;
gross_sal= bas_sal + med_al + h_rent;
printf("\nRameshs Gross Salary = %f ", gross_sal);
getch();
}