Abdurahman Lab 1
Abdurahman Lab 1
CS-201L
Data Structures and
Algorithms
Lab 01
Lab Tasks:
Algorithm:
Algorithm:
1. Initialize a loop variable i to 2.
2. While i is less than or equal to 100:
o Print i.
o Increment i by 2.
1
1 2
1 23
1 234
1 2345
Algorithm:
1. For each row i from 1 to 5:
o For each column j from 1 to i:
Print i followed by a space.
o Print a newline after each row.
Algorithm:
1. Define a function add(a, b) that takes two integers.
2. Inside the function, return the sum of a and b.
3. In the main program, call the function with two
user-provided numbers and print the result.
Algorithm:
1. Define a function square(a,b) that takes two integer.
2. Inside the function, return a * a & b*b .
3. In the main program, call the function with two
user-provided numbers and print the results.
Algorithm:
1. Define a function calc(a, b, c) that takes two integers and an
operator.
2. Inside the function, use a switch statement to perform the
operation based on the operator:
o If the operator is '+', return the sum.
3. In the main program, prompt the user for two numbers and an
operator, then call the function and print the result.
Conclusion
The tasks above outline how to perform various operations using loops and functions in
programming. They demonstrate fundamental programming concepts such as iteration, function
definition, and user input handling. By implementing these algorithms, one can create simple but
effective programs that illustrate core programming principles.