Assigenment #1
Assigenment #1
John’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.
PROGRAM:
#include <stdio.h>
int main()
{
float basic_salary, dearness_allowance, house_rent_allowance, gross_salary;
return 0;
}
RESULT:
Q#2)
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 .
PROGRAM:
int main()
{
float distance_km, distance_m, distance_ft, distance_in, distance_cm;
printf("Enter the distance between the two cities (in kilometers): ");
scanf("%f", &distance_km);
return 0;
}
RESULT:
Enter the distance between the two cities (in kilometers): 200
Distance in meters: 200000.00 m
Distance in feet: 656168.00 ft
Distance in inches: 7874020.00 in
Distance in centimeters: 20000000.00 cm
Q#3)
Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a
program to convert this temperature into Centigrade degrees.
PROGRAM:
int main()
{
float temp_fahrenheit, temp_celsius;
return 0;
}
RESULT:
Q#4)
The length & breadth of a rectangle and radius of a circle are input through the
keyboard. Write a program to calculate the area & perimeter of the rectangle, and the
area & circumference of the circle.
PROGRAM:
int main()
{
float length, breadth, radius; float rectangle_area, rectangle_perimeter;
float circle_area, circle_circumference;
printf("Circle:\n");
printf("Area: %.2f square units\n", circle_area);
printf("Circumference: %.2f units\n", circle_circumference);
return 0;
}
RESULT:
Rectangle:
Area: 690.00 square units
Perimeter: 106.00 units
Circle:
Area: 706.86 square units
Circumference: 94.25 units
Q#5)
Two numbers are input through the keyboard into two locations C and D. Write a
program to interchange the contents of C and D.
PROGRAM:
#include <stdio.h>
int main()
{ int C, D, temp;
temp = C;
= D;
= temp;
return 0;
}
RESULT:
Q#6)
If a five-digit number is input through the keyboard, write a program to calculate the
sum of its digits.
(Hint: Use the modulus operator ‘%’)
PROGRAM:
int main()
{
int num, digit, sum = 0;
return 0;
}
RESULT:
Q#7)
If a five-digit number is input through the keyboard, write a program to reverse the
number.
PROGRAM:
int main() {
int original_num, reversed_num = 0;
return 0;
}
RESULT:
Q#8)
If a four-digit number is input through the keyboard, write a program to obtain the
sum of the first and last digit of this number.
PROGRAM:
int main() {
int num, first_digit, last_digit, sum;
return 0;
}
RESULT:
Q#9)
In a town, the percentage of men is 52. The percentage of total literacy is 48. If total
percentage of literate men is 35 of the total population, write a program to find the
total number of illiterate men and women if the population of the town is 80,000.
PROGRAM:
int main() {
int total_population = 80000; int percent_men = 52; int percent_literacy =
48;
int percent_literate_men = 35;
return 0;
}
RESULT:
Q#10)
A cashier has currency notes of denominations 10, 50 and
100. If the amount to be withdrawn is input through the keyboard in hundreds, find the
total number of currency notes of each denomination the cashier will have to give to
the withdrawer.
PROGRAM:
int main() {
int amount_in_hundreds, num_100_notes, num_50_notes, num_10_notes;
remaining_amount %= 50;
return 0;
}
RESULT:
Q#11)
If the total selling price of 15 items and the total profit earned on them is input
through the
PROGRAM:
int main() {
float selling_price, profit, cost_price;
return 0;
}
RESULT:
Q#12)
If a five-digit number is input through the keyboard, write a program to print a new
number by adding one to each of its digits. For example if the number that is input is
12391 then the output should be displayed as 23402.
PROGRAM:
int main() {
int originalNumber, newNumber = 0;
int digit, modifiedDigit;
return 0;
}
RESULT:
Q#13)
While purchasing certain items, a discount of 10% is offered if the quantity purchased
is more than 1000. If quantity and price per item are input through the keyboard, write
a program to calculate the total expenses.
PROGRAM:
int main() {
int quantity;
float pricePerItem, totalExpenses;
return 0;
}
RESULT:
Q#14)
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
PROGRAM:
int main() {
float basicSalary, hra, da, grossSalary;
return 0;
}
RESULT:
Q#15)
If cost price and selling price of an item is input through the keyboard, write a
program to determine whether the seller has made profit or incurred loss. Also
determine how much profit he made loss he incurred
PROGRAM:
int main() {
float costPrice, sellingPrice, profitOrLoss;
if (profitOrLoss > 0) {
printf("Congratulations! You made a profit of $%.2f\n", profitOrLoss);
} else if (profitOrLoss < 0) {
printf("Oops! You incurred a loss of $%.2f\n", -profitOrLoss);
} else {
printf("No profit, no loss. You broke even!\n");
}
return 0;
}
RESULT: