Sale!

CSC326 Lab Assignment 1 Solved

$35.00

Category:

Description

5/5 - (1 vote)

Operating Systems
Problem 1:

Write a program that displays the following text. Note that there are multiple
ways to code this program.
*******************************************************
* ” Everybody should learn how to program a computer *
* because it teaches you how to think ” *
*******************************************************
• Submit your solution in a file called ”Problem1.c”.

Problem 2:

Write a C program that considers three variables w and l of type integers
representing the width and length of a rectangle, and r of type integer representing the radius of a triangle. The variables w, l and r have the following
values 2, 11 and 5, respectively. Your program should initialize two new variables areaRectangle and areaCircle to return the area of the rectangle and
the circle, respectively.
Sample input/output:
The area of the rectange (w=2, l=11) is 22
The area of the circle of radius r=5 is 78.539816
Note: In order to get the π value, you may assume it is has the value of
3.14 or you may use the ”math.h” library by including the following ” #include <math.h>” header and then use ”M PI”.
• Submit your solution in a file called ”Problem2.c”.
1

Problem 3:

Write a C program that considers three numbers a, b and c. Initialize the
three variables to have the following values 3 , 8 and 5, respectively. Then,
create a function ”Average” that takes as input the three variables and returns if the average of the three variables. Use your method in order to
compute the average and display the results.
Sample input/output:
The average is 5.33
• Submit your solution in a file called ”Problem3.c”.

Problem 4:

Write a C program that considers two points A and B in the xy-plane, having
the following coordinates: A(2,4) and B (3,15). Create a function ”distance”
that computes the Manhattan distance between any two points taking as
input the coordinates of the points and returning the distance between them.
The Manhattan distance is computed as the sum of the absolute differences
between the two points as follows:
D = |xA − xB| + |yA − yB| (1)

Use your function to compute the Manhattan distance between A and B
and display the results as shown below.
Note: In order to get the absolute value of a number, you may need to use
the ”math.h” library by including the following ” #include <math.h>” header
and then call the function ”fabs(a)” that returns the absolute value of a.

Sample input/output:

The Manhattan distance between A and B is 12.00
• Submit your solution in a file called ”Problem4.c”.
2