Student Name : AYUSH PRATAP SINGH
Student UID : 25LBCS1367
Section : 06
Course Name : PROGRAMMING FOR PROBLEM
SOLVING
Course Code : 25CSH-107
School of Computer Science and Engineering 1
INDEX PAGE
S. No. Experiment Title of the Date Page No. Signature
No. Experiment
01. 1.1 Write a program that reads 03-05
two nos. from a keyboard
and gives their addition,
subtraction, multiplication,
division and modulo.
02. 1.2 The distance between two 06-08
cities (In KM) is input through
a keyboard. Write a program
to convert and print this
distance in meters, feet,
inches & centimeters.
Signature of Faculty: _________________________
2
Experiment-1.1
Name: Ayush Pratap Singh Reg. No. /Acc. No./ UID: 25LBCS1367
Laboratory: PROGRAMMING FOR Code: 25CSH-107
PROBLEM SOLVING
Programme/Discipline: BTech CSE Section: 06
Date of Experiment: Date of Submission:
Write a program that reads two nos. from a keyboard and gives their addition,
Experiment Title:
subtraction, multiplication, division and modulo.
Objective:
Write a program that reads two nos. from key board and gives their addition, subtraction,
multiplication, division and modulo.
Theory:
Arithmetic operations are fundamental operations in programming. They include:
● Addition (+): Adds two numbers.
● Subtraction (-): Subtracts the second number from the first.
● Multiplication (*): Multiplies two numbers.
● Division (/): Divides the first number by the second (except when the divisor is zero).
● Modulo (%): Finds the remainder when the first number is divided by the second.
Algorithm/Methodology:
1. Start the program.
2. Prompt the user to enter two numbers.
3. Read the input values from the keyboard.
4. Perform addition, subtraction, multiplication, division, and modulo operations.
5. Display the results.
6. End the program.
3
Flowchart:
Implementation:
#include <stdio.h>
int main() {
int num1, num2;
// Input two numbers
printf("Enter first number: ");
scanf("%d", &num1);
4
printf("Enter second number: ");
scanf("%d", &num2);
// Perform calculations
printf("Addition: %d\n", num1 + num2);
printf("Subtraction: %d\n", num1 - num2);
printf("Multiplication: %d\n", num1 * num2);
// Check for division by zero
if(num2 != 0) {
printf("Division: %d\n", num1 / num2);
printf("Modulo: %d\n", num1 % num2);
} else {
printf("Division and modulo by zero not allowed.\n");
return 0;
Output:
Let’s assume the user enters the following numbers:
Enter first number: 12
Enter second number: 5
The program will output:
Addition: 17
Subtraction: 7
Multiplication: 60
Division: 2
Modulo: 2
5
Experiment-1.2
Name: Ayush Pratap Singh Reg. No. /Acc. No./ UID: 25LBCS1367
Laboratory: PROGRAMMING FOR Code: 25CSH-107
PROBLEM SOLVING
Programme/Discipline: BTech CSE Section: 06
Date of Experiment: Date of Submission:
The distance between two cities (In KM) is input through a keyboard. Write a
Experiment Title:
program to convert and print this distance in meters, feet,
inches & centimeters.
Aim:
To develop a program that converts the distance between two cities (input in kilometers) into meters,
feet, inches, and centimeters.
Objective:
To take user input for the distance in kilometers.
● To apply conversion formulas to calculate distances in different units.
● To display the results in a well-formatted manner.
● To understand fundamental programming concepts such as input handling,
mathematical operations, and output formatting.
Input Used:
Distance between two cities (in kilometers), entered through the keyboard.
Procedure:
1. Start the program.
2. Prompt the user to enter the distance between two cities in kilometers.
3. Convert the given distance into meters, feet, inches, and centimeters using predefined
conversion factors:
o Meters = Kilometers × 1000
o Feet = Kilometers × 3280.84
o Inches = Kilometers × 39370.1
o Centimeters = Kilometers × 100000
4. Display the converted values on the screen.
5. End the program.
6
Algorithm/Methodology:
1. Start.
2. Input the distance in kilometers (km).
3. Convert the distance using the following formulas:
o meters = km × 1000
o feet = km × 3280.84
o inches = km × 39370.1
o centimeters = km × 100000
4. Display the results.
5. Stop.
Code Implementation:
#include <stdio.h>
int main() {
double km; // distance in kilometers
// Input distance
printf("Enter distance in kilometers: ");
scanf("%lf", &km);
// Conversions
double meters = km * 1000;
double centimeters = km * 100000;
double feet = km * 3280.84; // 1 km = 3280.84 feet
double inches = km * 39370.1; // 1 km = 39370.1 inches
// Print results
printf("Distance in meters: %.2lf m\n", meters);
printf("Distance in centimeters: %.2lf cm\n", centimeters);
printf("Distance in feet: %.2lf ft\n", feet);
printf("Distance in inches: %.2lf in\n", inches);
return 0;
7
Output:
Let's assume the user enters:
Enter distance in kilometers: 5
The program will output:
Distance in meters: 5000.00 m
Distance in centimeters: 500000.00 cm
Distance in feet: 16404.20 ft
Distance in inches: 196850.50 in