0% found this document useful (0 votes)
3 views

Assignment

Uploaded by

pikor94551
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment

Uploaded by

pikor94551
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Course Name:

Computer Programming

Course Code

Submitted to:

Md. Jamil Uddin


Lecturer
East Delta University

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);

dearness_allowance = 0.4 * basic_salary;


house_rent_allowance = 0.2 * basic_salary;

gross_salary = basic_salary + dearness_allowance + house_rent_allowance


printf("Gross Salary = %.2f\n", gross_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;

printf("Enter distance in kilometers: ");


scanf("%f", &kilometers);
meters = kilometers * 1000;
centimeters = meters * 100;
inches = meters * 39.3701;
feet = meters * 3.28084;

printf("Meters: %.2f\n", meters);


printf("Feet: %.2f\n", feet);
printf("Inches: %.2f\n", inches);
printf("Centimeters: %.2f\n", centimeters);
return 0;
}

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;

printf("Aggregate Marks = %.2f\n", aggregate);


printf("Percentage = %.2f\n", percentage);

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;

printf("Enter the length of the rectangle: ");


scanf("%f", &length);

printf("Enter the breadth of the rectangle: ");


scanf("%f", &breadth);

printf("Enter the radius of the circle: ");


scanf("%f", &radius);

float areaRectangle = length * breadth;


float perimeterRectangle = 2 * (length + breadth);
float areaCircle = PI * radius * radius;
float circumferenceCircle = 2 * PI * radius;
printf("Rectangle Area: %.2f\n", areaRectangle);
printf("Rectangle Perimeter: %.2f\n", perimeterRectangle);
printf("Circle Area: %.2f\n", areaCircle);
printf("Circle Circumference: %.2f\n", circumferenceCircle);

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.

You might also like