Professional Documents
Culture Documents
Defination For Finals PDF
Defination For Finals PDF
css
Copy code
for(int i = 1; i <= 10; i++) {
cout << i << endl;
}
2. Counter control loops:
A counter control loop is a type of repetitive control structure that executes a set of
statements for a specific number of times.
Example: A for loop that prints numbers from 1 to 10
css
Copy code
for(int i = 1; i <= 10; i++) {
cout << i << endl;
}
3. For Loop:
A for loop is a repetitive control structure that allows the execution of a set of statements
repeatedly until a certain condition is met.
Example: A for loop that prints numbers from 1 to 10
css
Copy code
for(int i = 1; i <= 10; i++) {
cout << i << endl;
}
4. Sentinel Control loops:
A sentinel control loop is a type of repetitive control structure that executes a set of
statements until a specific value, known as the sentinel value, is encountered.
Example: A while loop that reads numbers until a sentinel value of -1 is encountered
c
Copy code
int num;
cout << "Enter a number (-1 to stop): ";
cin >> num;
while(num != -1) {
cout << "You entered " << num << endl;
cout << "Enter a number (-1 to stop): ";
cin >> num;
}
5. While loop:
A while loop is a repetitive control structure that executes a set of statements repeatedly
until a certain condition is met.
Example: A while loop that prints numbers from 1 to 10
bash
Copy code
int i = 1;
c
Copy code
int num;
do {
cout << "Enter a number (-1 to stop): ";
cin >> num;
cout << "You entered " << num << endl;
} while(num != -1);
7. Functions:
Functions are self-contained blocks of code that perform a specific task. They can be
divided into built-in functions, user-defined functions, inline functions, and recursive
functions.
Example: A user-defined function that returns the sum of two numbers
c
Copy code
int sum(int a, int b) {
return a + b;
}
int main() {
int result = sum(5, 10);
cout << "The sum is " << result << endl;
return 0;
}
8. Towers of Hanoi:
The Towers of Hanoi is a classic mathematical puzzle that consists of three rods and a
number of disks of different sizes. The objective is to move the entire stack to another
rod, obeying the following simple rules: only one disk can be moved at a time, each
move consists of taking the upper disk from one of the stacks and placing it on top of
another stack or on an empty rod, and no larger disk may be placed on top of a smaller
disk.
Example: Recursive function to solve the Towers of Hanoi problem
java
Copy code
void hanoi(int n, char source, char auxiliary,
abdullahch7047@gmail.com
please also do remaining definations
!
9. Single Dimensional Arrays:
A single dimensional array is a collection of elements of the same data type that are
accessed using an index. The index starts from 0 and goes up to size-1, where size is
the total number of elements in the array.
Example: Declaration and initialization of a single dimensional integer array
python
Copy code
int arr[5] = {1, 2, 3, 4, 5};
10. Passing as an argument to the function:
In C++, we can pass arrays as arguments to functions. The array is passed as a pointer
to its first element.
Example: Function that takes an array as an argument and returns its sum
16. Pointers:
A pointer is a variable that stores the memory address of another variable. It is declared
using the * operator.
Example: Declaring and using a pointer variable