SP Lab 1-Section1
SP Lab 1-Section1
Instructor:
Sawsan Alodibat ([email protected])
Total Mark / 10
Lab #1 Objectives
● Basics of Lab environment: Dealing with text editor, the compiler, the (code blocks) IDE
Page 1 of 4
Part I: Lab Example
Objective: The student will implement a simple calculator program that performs the basic arithmetic
operations: addition, subtraction, multiplication, and division.
Introduction:
● Write a program where the user can input two numbers and the program will perform all four
basic arithmetic operations (addition, subtraction, multiplication, and division) on those
numbers.
● The program will display the result of each operation.
Steps to Follow:
1. Declare two float variables to store the numbers input by the user (Number1, and Number2).
2. Declare variables to store the results of each operation (additionResult, subtractionResult, and
multiplicationResult).
3. Show welcome message to the user (“Welcome to your name Calculator”)
4. Ask the user to input two numbers using scanf().
5. Perform addition, subtraction, and multiplication directly.
6. Display the results for each operation using printf().
7. Perform division and print it directly without defining a variable.
Sample Output
Results:
Addition Result: 14.000000
Subtraction Result: 6.000000
Multiplication Result: 40.000000
Division Result: 2.500000
Page 2 of 4
PART II: Lab Exercise
On the desktop, create a folder named Lab1 followed by your id inside it Create project named
Lab1Ex1.
Exercise 1 – Conversion a unit in Meter into Kilometer, Inch, Centimeter, and Foot
Exercise Objectives
Using simple input and output statements
Using arithmetic operators
✔ Using comments
Problem Description
Write a program in C that converts an input numeric unit in Meter to give the equivalent value in KM,
CM, Inch, and Foot. Write a personalized greeting at the beginning.
● Greeting Message: The program should start by printing a message that says:
o Greetings from your full name.
● Prompt the user to enter a value in Meter.
● Convert the input unit in meter into Kilometer, Centimeter, Inch, and foot using the following
formulas:
o 1 Meter= 0.001 Kilometer.
o 1 meter=100 Centimeter.
o 1 meter=39.3701 Inch.
o 1 meter=3.2808 Foot.
● Print the result.
Sample Output
Page 3 of 4
PART III: Extra Lab Exercises
Write a C program that accepts two input integers, stores them in variables X and Y, respectively, and
then swaps the two variables’ values.
For example, if the user’s first input is 35 (stored in variable X) and the second input is 99 (stored in
variable Y), then the program has to swap the variables values, so that 35 will be stored in Y and 99 will
be stored in X.
Write a C program that reads in the radius of a sphere, computes and prints the sphere’s volume based
on the following equation for computing volume of sphere:
Page 4 of 4