0% found this document useful (0 votes)
8 views10 pages

EXERCISE 5 PC File

The document outlines a menu-driven program for performing various matrix operations, including single and two-matrix functions such as addition, subtraction, and multiplication, as well as string operations like input, length calculation, copy, and reverse. It emphasizes modular programming by defining separate functions for each operation and using a loop for user interaction. Learning outcomes include understanding matrix and string concepts, as well as writing maintainable code.

Uploaded by

geekygod07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

EXERCISE 5 PC File

The document outlines a menu-driven program for performing various matrix operations, including single and two-matrix functions such as addition, subtraction, and multiplication, as well as string operations like input, length calculation, copy, and reverse. It emphasizes modular programming by defining separate functions for each operation and using a loop for user interaction. Learning outcomes include understanding matrix and string concepts, as well as writing maintainable code.

Uploaded by

geekygod07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

EXERCISE 5

Problem Statement: Write a menu driven programme for matrices to do the


following operations depending whether the operations required one or two
matrices.
Theory:
Matrices are foundational to linear algebra and serve as essential tools in
computer science, especially in graphics, data analysis, machine learning, and
scientific computing.
The program performs both single-matrix operations (like transpose, scalar
multiplication, or determinant) and two-matrix operations (like addition,
subtraction, and multiplication)
Algorithm:
1. Start
2. Define Functions:

❖​ Input Function​
Define inputMatrix() to:​
Accept rows and columns.​
Use nested loops to input matrix elements.​

❖​Display Function​
Define printMatrix() to:​
Accept matrix and dimensions.​
Use nested loops to print each element.​

❖​Add Function​
Define addMatrices() to:​
Take two matrices.​
Perform element-wise addition.​
Store and return result.​

❖​Subtract Function​
Define subtractMatrices() to:​
Take two matrices.

Perform element-wise subtraction.​


Store and return result.​
❖​Multiply Function​
Define multiplyMatrices() to:​
Multiply two matrices if compatible.​
Store result using row-column dot product.​

❖​Transpose Function​
Define transposeMatrix() to:​
Swap rows and columns of input matrix.​

❖​Scalar Multiply Function​


Define scalarMultiply() to:

Multiply each matrix element by scalar.​

3. In main() function:

Use a loop (do-while) to:​


->Display Menu​
->Read user choice​
->Based on choice:​
→Call appropriate functions.​
→ Perform matrix operations.​
→ Display results.

4. If choice is 6:

→Display farewell message.​


→Exit loop.​
5. End

Learning Outcomes:

1.Gained a solid foundation in matrix concepts such as addition, subtraction,


multiplication, transpose, and scalar operations.

2.By breaking down the logic into functions, understood how to write
modular, reusable, and maintainable code.

3.Learnt how to design interactive, user-friendly programs that execute


tasks based on user input via menus and switch-case logic.
Source Code:
Output:
Problem Statement: Write a program to find string length
Algorithm:
1.​ Start
2.​ Input a string (name) from the user.
3.​ Initialize a counter l = 0 and traverse the string character by character.
4.​ Increment the counter until the null character '\0' is found.
5.​ Display the length of the string and end the program.
6.​ End
Source Code:

\
Output:
Problem Statement: Write a program to copy a string
Algorithm:

1.​ Start
2.​ Input a string from the user and store it in array a.
3.​ Initialize index i = 0.
4.​ Copy each character from a[i] to b[i] until a[i] =='\0'.
5.​ Terminate b with '\0 and display the copied string.
6.​ End

Source Code:​

Output:
Problem Statement: Write a program to reverse a string.

Algorithm:

1.​ Start
2.​ Input a string from the user and store it in array a.
3.​ Find the length of the string by traversing until the null character
('\0').
4.​ Copy characters from the end of a to the beginning of b using
reverse indexing.
5.​ Add null character at the end of b, and display the reversed string.
6.​ End

Source Code:

Output:
EXERCISE 8
Problem Statement: Write a program to perform the following operations on
strings without using string functions.
Theory:
This C program is designed to perform various string operations—input, display, find
length, copy, and reverse—using modular functions and a menu-driven interface.
Each operation is encapsulated in a separate function to promote clarity, reusability,
and maintainability. The user interacts with the program through a looping menu that
calls the appropriate function based on the user's choice.
Algorithm:
1.​ Start
2.​ Define functions for string input, output, length calculation, copy, and
reverse.
3.​ Display menu repeatedly and read user’s choice:
4.​If choice is:​
1 → Input string​
2 → Print string​
3 → Calculate and display length​
4 → Copy string and display copy​
5 → Reverse string and display result​
6 → Exit program
5.​ Use switch-case to call appropriate functions based on user input.
6.​ Loop until the user selects Exit.
7.​ End.
Source Code:
Output:

Learning Outcomes:
1.By breaking down the logic into functions, I understood how to write modular,
reusable, and maintainable code.
2.Gained a solid foundation in string concepts such as print, copy,reverse.

You might also like