You are currently viewing 10th Class Computer New Course Data & Repetition Unit-04

10th Class Computer New Course Data & Repetition Unit-04

Q.1 Multiple choice questions.

  1. An array is a ____________________ structure.

a) loop

b) control

c) data (Correct Answer)

d) conditional

2. Array elements are stored at ____________________ memory locations.

a) contiguous (Correct Answer)

b) scattered

c) divided

d) none

3. If the size of an array is 100, the range of indexes will be ____________________.

a) 0-99 (Correct Answer)

b) 0-100

c) 1-100

d) 2-102

4. ____________________ Structure allows repetition of a set of instructions.

a) Loop (Correct Answer)

b) Conditional

c) Control

d) Data

5. ____________________ is the unique identifier, used to refer to the array.

a) Data type

b) Array name (Correct Answer)

c) Array size

d) None

6. Array can be initialized ____________________ declaration.

a) at the time of (Correct Answer)

b) after

c) before

d) both a & b

7. Using loops inside loops is called ____________________ loops.

a) For

b) While

c) Do-While

d) Nested (Correct Answer)

8. ____________________ Part of for loop is executed first.

a) Condition

b) Body

c) Initialization (Correct Answer)

d) Increment/Decrement

9. ____________________ make it easier to read and write values in array.

a) Loops (Correct Answer)

b) Conditions

c) Expressions

d) Functions

10. To initialize the array in a single statement, initialize it ____________________ declaration.

a) at the time of (Correct Answer)

b) after

c) before

d) both a & b

Q.2 Define the following.

1) Data Structure

Data structure is a container to store collection of data items in a specific layout.

2) Array

An array is a data structure that can hold multiple values of same data type, e.g. an int array can hold multiple integer values, a float array can hold multiple real values and so on.

3) Array Initialization

Assigning values to an array for the first time, is called array initialization. An array can be initialized at the time of its declaration, or later. Array initialization at the time of declaration can be done in the following manner.

Data_type array_name[N] ={value1, value2, value3, ………, valueN};

Float height[5] = {5.7, 6.2, 5.9, 5.0,6.2};

4) Loop Structure

If we need to repeat one or more statements, then we use loops. For example, if we need to write Pakistan thousand times on the screen, then instead of writing printf(“Pakistan”); a thousand time, we use loops. We write only 3 or 4 lines of code and we get thousand time Pakistan printed on the screen.

5) Nested Loops

A loop inside another loop is called nested loop.

Q.3 Briefly answer the following questions.

1) Is loop a data structure? Justify your answer.

Answer:

No, loop is not a data structure. Loop is programming construct which runs until and the provided condition is true.

2) What is the use of nested loops?

Answer: Use of Nested Loops

When we want to repeat a pattern for multiple times, we use nested loops. For example, if we want to display the word “Pakistan” 10 times then we can do this by writing the code of displaying the word “Pakistan” in loop that runs 10 times.

3) What is the advantage of initializing an array at the time of declaration?

Answer: Advantages of initialization of an array

The main advantage of array initialization at the time of declaration is to reduce the line of codes, memory, and time. Array initialization can be done on the same line at the time of declaration, but if we did not initialize it at declaration time then we initialize each element of array one by one.

4) Describe the structure of for loop.

Answer: Structure of for loop

In C programming language, we can see the structure of for loop as below.

for(initialization; condition; increment/decrement)

{

        Code to repeat

}

In the above syntax,

  1. Initialization is the first part to be executed in for loop. Here we initialize our counter variable and then move to the condition part.
  2. Condition is checked, and if it turns out to be false, then we come out of the loop.
  3. If condition is true, then body of the loop is executed.

After executing body of the loop, the counter variable increases or decreases depending on the logic used and again we move to the step 2.

5) How can you declare an array? Briefly describe the three parts of array declaration.

Answer: Array Declaration

In C language, an array can be declared as follows:

data_type array_name[array_size]

Where

  • Data_type: type of data to be stored in array
  • Array_name: identifier of array
  • Array_size: maximum number of elements that can be stored

Example: following is the declaration of a float type array that holds marks of 20 students.

float marks[20];

Programming Exercises

Exercise 1 Part a: Use loops to print the following output on console.

*****

*****

*****

PTB Class 10th Computer Programming Exercise 1 part a

Output

PTB 10th class computer exercise 1 Part a answer

Exercise 1 Part b: Use loops to print the following output on console.

Unit4Q1Partb

Output

Exercise 2: Write a program that takes two positive integers a and b as input and displays the value of ab.

PTB Class 10th Computer Programming Exercise Q 02

Output

PTB 10th Computer Unit 4 Q2 Answer

Exercise 3: Write a program that takes two numbers as input displays their Greatest Common Divisor(GCD) using Euclidean method.

Unit4ProgrammingExercise3_code

Output

Unit4ProgrammingExercise3_answer

Exercise 4: Write a program to display factorial numbers from 1 to 7. (Hint: Use nested loops)

PTB 10th class Computer Ex 4

Output

PTB 10th Class Computer Ex 4_ answer

Exercise 6: Write a program that declares and initializes an array of 7 elements and tell how many elements in the array are greater than 10.

PTB 10th class Computer Ex 6

Output

PTB 10th class Computer Ex 6 answer

Recommended

10th Class Computer New Course User Interaction Unit-02

10th Class Computer New Course User Interaction Unit-02 Q.1 Multiple choice questions. printf is used to print ____________________ type of data. a) int b) float c) char d) All of them (Correct Answer) 2. scanf is a ____________________ in C programming language. a) keyword b) library c) function (Correct Answer) d) none of them 3. […]

9th Computer New Course Networks Unit-03

9th Computer New Course Networks Unit-03 3.1 Choose the correct option. The IPv4 address is made up of ____________________ binary bits. i. 31 ii. 29 iii. 32 (Correct Answer) iv. 30 2. Routing is the process of taking data from one device and sending it to another device in different ____________________. i. Channel ii. Network […]

Buy Best Stationery Products in Pakistan

Piano Ballpoint Pen

Piano Ballpoint Pen

ORO Trimetal Pencil

ORO Trimetal

Dollar Clipper Pen

UHU 10×7 ml Pack of 10 PCs

UHU 10×7 ml Pack of 10 PCs

Glue Stick 8g Pack Of 12 PCs

Glue Stick 8g

Color Pencils Box of 12 PCs

Deer Multi Color Pencils

For more stationery items please visit     :     https://stationerystore.pk