Assignment
Assignment
Computer Programming
Course Code
Submitted to:
Submitted by
Name:
ID:
Department: EEE
Date of submission:
Problem 1: 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.
Solution:
#include <stdio.h>
int main() {
float basic_salary, dearness_allowance, house_rent_allowance,
gross_salary;
printf("Enter Ramesh's basic salary: ");
scanf("%f", &basic_salary);
return 0;
}
Discussion:
This program was basic but as a beginner I have encountered some problem while running this
program. Such as, forgot to put semi-colon end of every line, assigning variable to the scan
function.
Problem 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.
Solution:
#include <stdio.h>
int main() {
float kilometers, meters, feet, inches, centimeters;
Discussion:
This program was quite similar to the previous one. I made some silly mistakes like forgot to put
inverted comma in the printf, and so on.
Problem 3: Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a
program to convert this temperature into Celsius degrees.
Solution:
#include<stdio.h>
int main (){
float fahrenheit,centigrade;
printf("Enter the temperature in fahrenheit:");
scanf("%f",&fahrenheit);
centigrade=(fahrenheit-32)*5/9;
printf("The temperature in centigrade:%.2f\n",centigrade);
return 0;
}
Discussion:
This one was one of the easy one, pretty much everything was straight forward. Like defining
variables, taking input using scanf, assign the equation and print it.
Problem 4: If the marks obtained by a student in five different subjects are input through the
keyboard, write a program to find out the aggregate marks and percentage marks obtained by the
student. Assume that the maximum marks that can be obtained by a student in each subject is
100.
Solution:
#include <stdio.h>
int main() {
int m1, m2, m3, m4, m5;
float aggregate, percentage;
printf("Enter marks in five subjects: ");
scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
aggregate = m1 + m2 + m3 + m4 + m5;
percentage = (aggregate / 500) * 100;
return 0;
}
Discussion:
This problem was some level of troublesome, at least the part where I tried to get all the array
input at the same time. And also made some silly syntax error too.
Problem 5: The length and breadth of a rectangle and radius of a circle are input through the keyboard.
Write a program to calculate the area and perimeter of the rectangle, and the area and circumference of
the circle.
Solution:
#include <stdio.h>
#define PI 3.1416
int main() {
float length, breadth, radius;
return 0;
}
Discussion:
Solving this problem took a bit of time as the question was little tricky. Took me a-lot of
attempts to solve it. Keeping track of all the variables was challenging too.