CSE1018Y_Labsheet1
-
Upload
masterarvin -
Category
Documents
-
view
1 -
download
0
description
Transcript of CSE1018Y_Labsheet1
Week 3: Computer Programming (C)
1. Write a program that displays the outline of a box five characters wide and
five characters tall. Use the ‘*’ character for the box outline.
2. Write a program to display the area and perimeter of a rectangle. Prompt
the user to enter the length and breadth (in cms.) of the rectangle.
3. Write a program that displays the sum and the product of three numbers
entered by the user.
4. Write a program to display the area and volume of a sphere given that the
user enters the radius of the sphere.
5. Write a program that prompts the user for coursework and exam marks in
a unit, and displays the unit mark calculated as 30% of the coursework
mark plus 70% of the exam mark.
6. Write a program that prompts the user for three integers, and then
displays, for each number entered,
• the number, • its double, • its square, and • its cube.
7. Write a program to display the ASCII code of a user-entered character,
then display the characters with ACSII codes one less than and one greater
than the code of the character entered.
8. Write a program to read two initials (letters), e.g. X and Y, and display
them in the form
Hello X.Y. The initials are to be entered from the keyboard in the same line of input.
9. Write a program that prompts the user to enter the numerators and
denominators of two fractions. The program should then display the
numerator and denominators of the fractions that represent:
a) the product of the two input fractions, and b) the sum of the two input fractions.
[Hint: If the numerators and denominators of the two fractions are n1, d1 and n2, d2, then the product is (n1* n2)/( d1* d2), and the sum is (n1* d2 + n2* d1)/( d1* d2). Avoid entering zero for d1 or d2!]
10. Write a program to calculate the estimated journey time of a train. The
program should request and read the distance in miles and the average
speed in miles per hour, and display the estimated journey time in hours
and minutes to the nearest minute.
Test your program with: a) Distance = 1.01, speed = 1. [Result should be 1 hour & 1 minute.] b) Distance = 1.005, speed = 1. [Result should be 1 hour & 0 minutes.]
11. Write a program to display the square root of a user-entered real number.
Use the function sqrt(float) from the Maths library <math.h>