# 10th class computer science chapter 4 Data and Repetition

## 10th class computer science chapter 4 Data and Repetition on Newsongoogle.com by Bilal Article

### shorts and simple Question & Answers

Q.1: Define Data Structures.
Ans:
Data structure is a container to store collection of data items in a specific layout.

Q.2: What is an Array?
Ans:
An array is a data structure that can hold multiple values of same data type and stores all the values at consecutive locations inside the computer memory.

Q.3: How we can declare an array of type int?
Ans:
If we want to declare an array of type int that holds the dally wages of a laborer for seven days, then we can declare it as follows:
Int dally_wage[7];

Q.4: How we can declare an array of float type?
Ans:
The example of the declaration of a float type array that holds marks of 20 students are given below. float marks[20];

Q.5: What is an Array Initialization?
Ans:
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.

Q.6. How we can initialize an array?
Ans:
Array initialization at the time of declaration can be done in the following manner. Data_type array_name[N] = {value1, value2, value3,……,valueN};

Q.7. Write down the example to declaration and initialization of a float array to store the heights of seven persons.
Ans:
float height[7] = (5.7, 6.2, 6.9, 6.1, 6.0, 5.5, 6.2);

Q.8: Can you declare an array without assigning the size of an array?
Ans:
No we cannot declare an array without assigning size.

Q.9: Write down the example to initializes an array of characters to store five vowels of English language.
Ans:
char vowels[5] = {‘a’, ‘e’, ‘I’, ‘o’, ‘u’);

Q.10: How we can initialize an array if we do not initialize at the time of declaration?
Ans:
If we do not initialize an array at the time of declaration, then we need to initialize the array elements one by one. It means that we cannot initialize all the elements of array in a single statement.

Q.11: Can we initialize all the elements of array in a single statement? Explain it with example.
Ans:
No, we cannot initialize all the elements of array in a single statement.

Q.12: How we can access array elements?
Ans:
Each element of an array has an index that can be used with the array name as array_name[index] to access the data stored at that particular index.

Q.13: What is important features using variables as array indexes?
Ans:
A very important feature of arrays is that we can use variables as array indices e.g.

Q.14: What is Loop?
Ans:
If we need to repeat one or more statements, then we use loops.
Example:if we need to write Pakistan thousand times on the screen, then instead of writing printf (“Pakistan”); a thousand times, we use loops.

Q.15: What structures of loop provided by C language?
Ans:
Following three structures are provided by C language:
For loop
While loop
Do While loop

Q.16: What is the General structure of loops?
Ans:
If we closely observe the process that humans follow for repeating a task for specific number of times then it becomes easier for us to understand the loop structures that C language provides us for
controlling the repetitions.

Q.17: Write down the General syntax of for loop.
Ans:
In C programming language, for loop has the following general syntax

Q.19: What part of for loop executed first?
Ans:
Initialization is the first part to be executed in a for loop.

Q.20: Find the output of below program:
Ans:
int main()
{
int i = 0, x = 0;
do
{
if(i % 5 == 0)
{
}
}
cout<<x;
x++;
++1;
while(i<10);
cout<<x;
getch ();
}
Output
012
Q.21: Find the output of below program:
Ans:
int main()
{
int i=0,x=0;
for(i=1;i<10;i*=2)
{
x++;
}
cout<<x;
}
cout<<x ;
getch ();
output
12344

Q.22: Define an Iteration.
Ans:
Iteration is the process where a set of instructions or statements are executed repeatedly for a specific number of time until a condition becomes false.

Q.23: What is the general structure of Nested Loops?
Ans:
We can observe that Code to repeat could be any valid C language code. It can also be another for loop e.g. the following structure is a valid loop structure.
for (initialization; condition; increment/decrement)
{
for (Initialization; condition; Increment/decrement)
{
Code to repeat
}

Q.24: What is nested loop structures?
Ans:
When we use a loop inside another loop, it is called nested loop structure.

Q.25: When do we use nested loops?
Ans:
When we want to repeat a pattern for multiple times, then we use nested loops, e.g. if 10 times we want to display the numbers from 1 10. We can do this by writing the code of displaying the numbers from 1-10 in another loop that runs 10 times.

Q.26: What is difference between Loops and Arrays?
Ans:
A variables can be used as array indexes, so we can use loops to perform different operations on arrays. If we want to display the whole array, then instead of writing all the elements one by one, we can loop over the array elements by using the loop counter as array index

Q.27: How many times a while loop should be printed?
Ans:
int main()
{
int i = 1;
i=i-1:
while(i)
cout<<“its a while loop”;
i++;
}
getch();
}
Output
Infinite Times.

Q.28: How we can use a loop to take input from user in an array of size 10?
Ans:
int a [10]; for (int i = 0; i< 10; i++)
scanf (“%d”, &a[i]);
display t

Q.29: Write down the code to display the elements of an array having 100 elements.
Ans:
The following code can be used to display the elements of an array having 100 elements:
for (int i = 0; i< 100; i++)
printf(“%d “, a[i]);

Q.30: Write down the code to add all the elements of an array having 100 elements.
Ans:
The following code can be used to add all the elements of an array having 100 elements:
int sum = 0;
for(int i = 0; i< 100; i++)
sum = sum + a[i];
printf(“The sum of all the elements of array is %d”, sum);

Q.31: Write down the example of while loop
Ans:
#include
int main()
{ int count=1;
{
}
while (count <= 4)
printf(“%d “, count);
getch();
count++;
} Output: 1234

Q.32: Define counter Variable in for loop?
Ans:
A counter variable is a variable that keeps track of the number of times a specific piece of code is executed.

Q.33: Describe use of counter variable in for loop?
Ans:
For loop use the counter variable whose values the loop. is increase or decrease with each repetition.

Ans:
A loop is not a data structure because data structure means it is a specific layout of computer memory to store collection of data items, while loop is used to repeat a set of statements.

Q.35: Define while loop?
Ans: A while loop in C programming language repeatedly executes a set of statements or instructions as long as the given condition is true.

Q.36: Describe the structure of while loop?
Ans:
while (condition)
{ } Statement or set of statements; or set of state

Q.37: What is the advantage of initialization array at the time of declaration?
Ans:
The following are the advantages of initializing an array at the time of declaration:

1. Save time
2. Save memory
3. CPU friendly
4. Define the size

### Multiple Choice Questions

##### MCQs

1. is a container to store collection of data items in a specific layout.
A. Software
B. Hardware
C. Data structure✅
D. Arrays
2. An is one of the most commonly used data structures.
A. Loop
B. Array✅
C. Flowchart
D. Algorithm
3. An is a data structure that can hold multiple values of same data type
A. Array✅
B. Memory
C. Loop
D. None
4. How we can declare an array of type int that holds the daily wages of a labors for seven days?
A. Int daily_wage [7]B. Int dally_wage [7];✅
C. Int dally_wage (7);
D. Int daily_wage [17]):
5 An array Index starts with Which one of the following is the size of int arr[9] assuming that int is of 4 bytes?
A. -1
B. 0✅
C. 1
D. 2
6 Which one of the following is the size of int arr[9] assuming that int is of 4 bytes?
A. 9
B. 40✅
C. 35
D. none
7. How can we initialize an array in C language?
A. int arr[2]=(10,20)
B. int arr(2)={10,20)|
C. int arr[2] = {10, 20);✅
D. int arr(2) = (10, 20)
8. Assigning values to an array for the first time, is called
A. Array filling
B. Array finalization
C. Array declaration
D. Array initialization✅
9. An array can be initialized at the time of its
A. Declaration✅
B. Initialization
C. Finishing
D. None
10. If we do not initialize an array at the time of declaration, then we need to initialize the array elements
A. one by one✅
B. two by two
C. three by three
D. together
11. An array can hold multiple integer values.
A. While
B. Int✅
C. Float
D. nested
12. A array can hold multiple real values.
A.For
B. Simple
C. Float✅
D. While
13. An important property of array is that it inside the computer memory.
A. stores all the values at consecutive locations✅
B. stores all the values at memory locations
C. does not stores all the values at consecutive – locations
D. stores only one values at consecutive locations
14. Each element of an array has an index that can be used with the as array_name[index] to access the data stored at that particular index.
A.Index
B. Loop
C. array location
D. array name✅
15. A very important feature of arrays is that we can use as array indexes.
A. Numbers
B. Variables✅
C. Constants
D. Integer
16. If we need to repeat one or more statements, then we use
A. Array
B. Repetition
C. Loops✅
D. All
17. C language provides kind of loop structures.
A. Three✅
B. Four
C. Five
D. Six

18. Which on from the following is not a type of loops?
A. For loop
B. Do While loop
C. Check loop
D. While loop✅
19. is the first part to be executed in a for loop.
A. Initialization✅
B. Declaration
C. Finalization
D. None
20. Each run of a loop is called an
A. Declaration
B. Repetition
C. Iteration✅
D. Running
21. When we use a loop inside another loop, it is called structure.
A. Do while loop
B. Else loop✅
C. Nested loop
D. While loop
22. When we want to repeat a pattern for multiple times, then we use
A. Repetition loop
B. Do while loop
C. Nested loops
D. Else loop✅
23. We can use inside loop structures.
A. loop structures✅
B. Sequence structure
C. While structure
D. Nested structure
24. We can use inside if structures in any imaginable manners.
A. While structure
B. Data structure
C. Loop Structure✅
D. if structures
25. As can be used as array indexes.
A.Variables✅
B.Loop
C.Data structures
D.Constants
26. We can use loops to perform different operations on
A. Information
B. Arrays✅
C. Loops
D. Data
27. Using, we can easily take input in arrays.
A. for Loops
B. Nested loop✅
C. Arrays
D. Loops
28. help us in reading the values from array.
A. loop✅
B. Array
C. Compiler
D. None
29. What is correct syntax of for loop?
A. for (initialization ; condition; increment /decrement)✅
B. for(increment/ decrement; initialization ; condition)
C. for (initialization , condition, increment/ decrement)
D. none
30. Can for loop contain another for loop?
A. No
B. Yes✅
C. Compilation Error
D. Runtime Error