Professional Documents
Culture Documents
Programming-Sheet3 - Answers
Programming-Sheet3 - Answers
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.
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.
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!