Comp Assignment
Comp Assignment
EB13/74168/24
QUESTION 1
#include <iostream>
#include <string>
struct Person {
string name;
int age;
};
int main() {
getline(cin, user.name);
return 0;
QUESTION 2
1. Variable:
o A variable is a storage location whose value can change during the execution of a
program.
o Example:
2. Constant:
o A constant is a storage location whose value cannot change once it's defined.
o It provides fixed data that remains the same throughout program execution.
o Example:
Variables are dynamic, while constants are immutable. Let me know if you'd like to explore more
examples!
QUESTION 3
Boolean expressions are essential in programming as they evaluate to either true or false, enabling
conditional logic and decision-making. They are used in:
Explanation:
number % 2 == 0: Checks if the remainder of the number divided by 2 is zero (indicating it's
even).
#include <iostream>
int main() {
int number;
if (number % 2 == 0) {
} else {
}
return 0;
QUESTION 4
#include <iostream>
int sum = 0;
sum += arr[i];
return sum;
int main() {
// Display results
cout << "Sum of array " << i + 1 << ": " << sums[i] << endl;
return 0;
QUESTION 5
Description: Instructions are executed in the order they appear, one after another.
Example:
START
END
2. Selection Control Structure (Conditional)
Description: Decisions are made based on conditions, using statements like if, else, or switch.
Example:
START
Read number
ELSE
Display "Zero"
ENDIF
END
Description: Repeated execution of a block of code using loops like while, for, or do while.
Example:
START
Set counter = 1
counter = counter + 1
ENDWHILE
END