Lab 1
Lab 1
Objective(s):
To be familiar with syntax and structure of C- programming.
To learn problem-solving techniques using C
Program: Write a Program to calculate and display the volume of a CUBE having its
height (h=10cm), width (w=12cm) and depth (8cm).
Algorithm:
1. Start
2. Define variables: h(int), w(int), d(int), vol(int)
3. Assign value to variables: h = 10, w=12, d=8
4. Calculate the volume as: vol = h*w*d
5. Display the volume (vol)
6. Stop
Flowchart:
Code: (Use comments wherever applicable)
#include<stdio.h>
void main()
{
//start the program
int h,w,d,vol; //variables declaration
h=10;w=12;d=8; //assign value to variables
vol=h*w*d; //calculation using mathematical formula
printf("The Volume of the cube is: %d",vol); //display the volume
getch();
//end the main program
}
Output :
The Volume of the cube is: 960
SAMPLE PROGRAMS
(Students are to code the following programs in the lab and show the output
to instructor/course teacher)
Instructions
Programs List
7. Write a program that reads an employee's number, his/her worked hours number in a
month and the amount he received per hour. Print the employee's number and salary
that he/she will receive at end of the month, with two decimal places.
8. Little John wants to calculate and show the amount of spent fuel liters on a trip, using
a car that does 12 Km/L. For this, he would like you to help him through a simple
program. To perform the calculation, you have to read spent time (in hours) and the
same average speed (km/h). In this way, you can get distance and then, calculate how
many liters would be needed. Show the value with three decimal places after the point.