You are on page 1of 4

Computer Programming

Lab Exam

Name: Ibrahim Wattoo ID: 190349 BEEE IIB

1) What are arrays. Write any 2 advantages of arrays. (0.5 marks)


Arrays are the data structures which are used to store the data. The variable of the array
represents the memory location at which the first item of the
array is stored.
Advantages:
 Array represent multiple date items of the same type in a single variable.
 In arrays, items can be accessed randomly by using the index number.

What is the difference between while and do while loop. (0.5 marks)
In while loop condition comes at the beginning of the loop
In while loop there is not semi colon at the end.
While loop do not executes if the condition is false.

Do while Loop:
In do while loop condition comes at the end.
In do while loop there needs to be the semi colon.
Do while executes the body once condition is false
3)Write a code of factorial using loops. (1.5 marks)

4) Why do we use functions in our code? (0.5 marks)


Functions are the piece of the codes which are used to perform a specific operation.
We can use a function again and again to perform a same task whenever needed.
The main reason for using the functions is for the reuseability of the code. Functions reduce the
code duplication.
We can write the code in a function which is being used at multiple places and then use that
function at those places
to perform that specific task.

5) Write a function which finds middle number in an array of any size. (2 marks)

MCQS:
1) a
2) c
3) c
4) a
5)c

You might also like