Uploaded by Hussin Ketout

CMPET 211 LAB 1

advertisement
Penn State Behrend
Electrical and Computer Engineering
Technology
CMPET 211 LABs
Instructor:
Dr. Hussin Ketout
Lab 1
Due: Before next lab (check CANVAS)
C Lab Report Submitted By:
Name: ………………………………………….
PSU ID: ………………………………………..
Lab is to be done individually and is not permitted to be collaboration. You may
use the internet to assist you for understanding knowledge, but it cannot be used as
a source for code.
Submit your response as a word document, there the name should be:
Lab1_xxxxx.doc (where “xxxxx” is your email ID) and upload to CANVAS.
You are encouraged to discuss the lab but you must do the coding yourself. You
must understand submitting code which is the work of other individuals is a
violation of the course Academic Integrity Policy and may result in a zero credit
for the assignment, or course failure and a report to the Academic Dishonesty
Board. You must also understand if you give your original work to another
individual, it could also result in a zero credit for the assignment, or course
failure and a report to the Academic Dishonesty Board.
Objective(s):


To be familiar with syntax and structure of C-programming.
To learn problem solving techniques using C
Problem:
Write a C Program to calculate and display the area of a rectangle where its height (h=45cm) and
its width (w=12cm).
Problem Analysis:
The problem is to calculate the area of a rectangle having its inputs variables identified as:
1. Height (integer type)
2. Width (integer type).
The output of the program is to display the Area. The output variable is identified as Area
(integer type).
During the execution of the program, you don’t need to provide any extra variables for this
problem.
The area of the rectangle is the multiplication of its height and width.
The mathematical formula to calculate area is:
Area= Height * Width
Input Variables
Processing Variables
Height (int)
Area=
Height* Width
Width (int)
Output Variables
Area (int)
Algorithm:
1. Start
2. Define variables: Height (int), Width (int), Area (int)
3. Assign value to variables: Height = 45, width=67
4. Calculate the Area: Area = Height*Width*d
5. Display the Area (Area)
6. Stop
Necessary header files
Stdio.h
Code:
//Following code is to calculate the area of rectangle
#include<stdio.h>
int main(void)
{ //start of the program
int Height,Width, Area;
//variables declaration
Height=45; Width=67;
//assign value to variables
vol=h*w*d;
//calculation the area using the mathematical formula
printf("The Volume of the cube is: %d",vol); //display the area
return 0;
//end the main program
}
Discussion and Conclusion
This is the first code written in C program. The program is focused on the calculation of a
rectangle for the given Height and Width. From this lab, I understood the basic structure of C
programming including the meaning of header files & steps of problem solving. Hence, area of a
rectangle is calculated and displayed.
Lab exercises (please code yourself and show the output to instructor):
Please, come ready to the LAB (Prepare the CODE)
1. Write a program to display “your Name, ID, Department and University name”.
2. Write a program to add, subtract, multiply, divide and calculate the modulus (remainder
of after an integer division) two numbers and display all the results.
3. Write a program to calculate area of a square having its side.
4. Write a program to calculate area of an circle having its radius.
Download