You are on page 1of 4

Admas University: Department of Computer Science

Structured Programming I: Worksheet I

Exercise I
1) Write a C++ program that solves any linear equation of the form ax + b = 0

2) Write a C++ program that calculate area of the following geometric figures

a) Square b) Rectangle, c) Right Triangle d) circle

3) Write a program that solves general quadratic equations of the forma ax 2 +bx +
c=0. A quadratic equation may have only one solution, two distinct solutions, or no
real solution.

4) Write a program that reads a natural number and print the reciprocal of the number

a) In decimal format

b) In fraction format

Example: if the input is 10, the outputs are

a) 0.1 in decimal format

b) 1/10 in fraction format

5) Write a program that performs addition of fraction numbers. The program takes two
fractions in a / b +c / d format and displays the output in e / f format.

6) Repeat question number 5 for the operations Subtraction, Multiplication and


Division.

7) Write a program that reads two integer numbers and swaps their value.

Exercise 2
1. Write a program that displays a remark based on their grade that is supplied from the
keyboard, the program should handle both upper case & lower case grades.

Page 1 of 4
Admas University: Department of Computer Science
Structured Programming I: Worksheet I

Rule:

Grade Remark

A Excellent

B Very Good

C Good

D Bad

F Very Bad.

Modify the above program to give the same Remark for

A and B: Above average

C: Average

D and F: Below average.

2. Write a program that requests the user to enter a number from the keyboard and tells
whether the number entered is zero, negative, or positive.

3. Write a program that displays Monday if the value entered is 1 or 2 or 3, Tuesday for 4 or
5, Wednesday for 6, Thursday for 7 or 8 and Friday for 9.

4. Write a C++ program that accepts two integer numbers form the user and calculate their
SUM or Difference or Product based on the arithmetic operator selected by the user
(note: Use switch case statement)

Page 2 of 4
Admas University: Department of Computer Science
Structured Programming I: Worksheet I

6. Write a program that reads a three digits number and displays the digits of the number
in reverse order

Example- If the input is 495, the output will be 594.

7. Write a program that accepts any number and checks whether a number is prime or not. And if
it is prime display "The number is prime", if it is not prime display "The number is not
prime".

(Hint:- An integer is said to be prime if it is divisible only by itself and by 1)

8. Write a program that calculates the factorial of a given natural number n and display the value
to the screen.

9. Write a program that accepts:

a. ASCII value and displays the corresponding character with the given ASCII value.

b. Accepts a character a - z or A-Z and display its ASCII value.

c. Accepts a character and displays the next character.

10. Write a C++ program that

a. Adds the 1 st N-natural numbers

b. Lists down all number between 1000 and 2000 that are divisible by 7

12. Write a C++ program that reads N numbers from the keyboard and displays the sum and their
average.

13. Write a program that continuously reads numbers from the keyboard until zero is given as
input and finally display the sum and average of the input numbers.

14. Write a program that continuously reads numbers from the keyboard until zero is given as
input and finally display the sum and average negative and positive numbers separately of.

15. Write a program that displays the maximum value from three integer number given as an
input.

16. Write a program for a simple Arithmetic Game

Page 3 of 4
Admas University: Department of Computer Science
Structured Programming I: Worksheet I

Description of the program


 Accepts two integer numbers X and Y
 Asks the user two answer X+Y
 If the answer is wrong, it provides two more trials by displaying “PLEASE TRY
AGAIN”
 Then it asks for X-Y( and provides same trial if the answer is wrong)
 Then Proceeds to X*Y( same trial)
 Then asks X/Y( an integer division with same trial )
 Finally the program loops of different inputs of X and Y or Terminates based on
the user’s Interest)

17. Write a program that outputs the following shapes from a single asterisk (*)

a.Equilateral Triangle
b. Square
c.Square with diagonal from top left corner to bottom right

Note: dimensions (number of rows and columns will be determined by the user at run time)

Page 4 of 4

You might also like