Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Computer Programming 1

Faculty of Computers & Information system


Level 1
Sheet #3
Using C++ :
1.Read one-character gender (M, m, F, f) and print the full gender (Female, Male
or unspecified).

4.Obtain a series of positive numbers from the keyboard and determine and display
their sum. Assume that the user types the sentinel value -1 to indicate “end of data
entry.”
7.Implement a simple algorithm to search for a specific element in an integer array

Using pointers
11.Write is_prime function that accept number given by user and return 1 if it is a
prime number and 0 otherwise.
13.Write a function max3grades which uses 3 parameters and returns the value of
the largest. Test the function in a program that determines the largest of 3 grades.

14. what is the output:


a.
b.

Output:
1
3
5
7
9
11
13
15
17
19

c.
15.What is the error? Can be more than one.
d.

1-The code may lead to an infinite loop. The loop condition x >= 1 will always be,
and it is decremented in each iteration. Therefore, x will never be less than 1,
resulting in an infinite loop.
2- we should declare the datatype of variable x as an int

e.

Break statement is missing

f.

1-We can only use int and char datatypes in the switch case.
2-We can only use break statement in switch case
16.Write a function that calculates and return the Sum of Series 1/1! + 2/2! + 3/3! +
……1/N!

You might also like