King Hussein Faculty of Computing Sciences
Department of Computer Science
Structured Programming Lab
Section#1
Instructor: Hammam Alakhras
In-Lab assignment #1 – Writing Simple C Programs
Lab Exercises
Exercise Ex. 1 Ex. 2 Ex. 3 Ex. 4
Mark /4 /1 /2 /3
Total Mark / 10
Lab #1 Objectives
⮚ Using IDE to create, compile, debug and run C programs.
⮚ Using simple input and output statements.
⮚ Identifying and using fundamental data types.
⮚ Using arithmetic operators
⮚ Using comments.
Page 1 of 5
Lab Exercises
Exercise 1–
Exercise Objectives
✔ Debugging simple programs
✔ Working with data types
Problem Description
A. Find the error in the following code. Add a comment next to each line causing an error.
The comment should explain why that line or part of the line is causing an error
Fix the code so that it runs without errors and produces reasonable output. Submit the fixed
code for grading
#include <stdio.h>
int main ()
char i = 'j';
char f = 'n';
int x='55'
printf(" %c is short for floating point", f);
return 0;
}
B. The code below does not print 11, why?
Submit your answer for grading
#include <stdio.h>
int main () {
int a = 1+ '10';
// DO NOT MODIFY ANYTHING BELOW THIS LINE.
printf(" %d", a);
return 0;
}
C. The code below does not print the character 'D', why? Submit your answer for grading
#include <stdio.h>
int main () {
char var = 'D';
// DO NOT MODIFY ANYTHING BELOW THIS LINE.
printf(" %d", var);
return 0;
Page 2 of 5
}
Exercise 2
Exercise Objectives
✔ Implement A flowchart
Problem Description
Consider the following flowchart, write a C program to properly implement the flowchart.
Copy and paste your code in response to this exercise.
Page 3 of 5
Exercise 3 –
Exercise Objectives
✔ basic problem solving
Problem Description
Using flowgorithm, construct the flowchart of a program that converts and print the area
of the Parallelogram, which is computed using the following equation:
Area = b X h
Organize your output as in the following Sample
Input the following Parallelogram’s information:
Base (b):
5
Height (h):
3
Parallelogram’s Area = 15
⮚ Submit your chart as flowgrithm file (a file with .fprg extension )
َ
Page 4 of 5
Exercise 4 –
Exercise Objectives
✔ basic problem solving
✔ Using simple input and output statements.
✔ Identifying and using fundamental data types.
✔ Using arithmetic operators
✔ Using comments.
Problem Description
Write a program to create a customer’s bill for a furniture shop. The shop sells 3 different
products with the unit price as following:
Table - 100 JD
Chair – 180 JD
Carpet – 120 JD
The program must read the quantity of each product purchased by a customer. It then
prints the Sub Total Price (for each item) and the Total Price in the following format:
QTY Description Unit Price SubTotal
=== ========== ======== ========
1 Table 100.00 100.00
1 Chair 180.00 180.00
2 Carpet 120.00 240.00
============================================================
Total Price 520.00 JD
Add your name as a comment at the beginning of the program
Page 5 of 5