0% found this document useful (0 votes)
21 views

Algorithms C Programs

Uploaded by

Siddhant patil
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)
21 views

Algorithms C Programs

Uploaded by

Siddhant patil
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/ 2

Algorithms for C Programs

1. C Program to Print Pyramids


Algorithm: 1. Start. 2. Accept the number of rows for the pyramid. 3. Use
nested loops: - Outer loop: Iterate over rows. - Inner loop: Print spaces and
then stars. 4. Print the pyramid pattern based on the loops. 5. End.

2. Find the Sum of Sine Series


Algorithm: 1. Start. 2. Input the value of x (in degrees) and number of terms
n. 3. Convert x from degrees to radians. 4. Initialize sum = 0. 5. For i = 1 to
n: - Compute (-1)^(i-1) * (x^(2i-1) / (2i-1)!). - Add to the sum. 6. Display the
sum. 7. End.

3. Menu-Driven Matrix Operations


Algorithm: 1. Start. 2. Display menu with options: - Add two 3x3 matrices.
- Transpose a 3x3 matrix. - Multiply two 3x3 matrices. 3. Accept user choice.
4. Based on choice: - For addition: - Input two matrices. - Add corresponding
elements. - Display result. - For transpose: - Input a matrix. - Swap rows and
columns. - Display result. - For multiplication: - Input two matrices. - Multiply
rows of the first matrix with columns of the second. - Display result. 5. Repeat
or exit. 6. End.

4. String Operations
Algorithm: 1. Start. 2. Input a string (or two strings where needed). 3.
Perform operations: - Length: - Count characters until the null character. -
Reverse: - Traverse string from end to start. - Equality check: - Compare
characters of two strings. - Palindrome: - Check if string reads the same
forward and backward. 4. Display results for each operation. 5. End.

5. Fibonacci Series Using Recursion


Algorithm: 1. Start. 2. Input the number of terms n. 3. Define recursive
function: - Base case: F(0) = 0, F(1) = 1. - Recursive case: F(n) = F(n-1) +
F(n-2). 4. Use a loop to display Fibonacci terms. 5. End.

6. Search an Element in an Array


Algorithm: 1. Start. 2. Input array size and elements. 3. Input the element
to search. 4. Use a loop: - Compare each element with the target. - If found,
display position and exit loop. 5. If not found, display “Element not found.” 6.
End.

1
7. Employee Details Operations
Algorithm: 1. Start. 2. Define structure for employee details: - Name, Des-
ignation, Gender, DOJ, and Salary. 3. Input details for multiple employees. 4.
Compute: - Total employees: Count entries. - Employees with salary >
20,000: Filter and display. 5. End.

8. Swap Two Numbers


Algorithm (Pointers): 1. Start. 2. Input two numbers. 3. Define a function:
- Accept two pointers. - Use a temporary variable to swap values. 4. Call the
function and display results. 5. End.

9. Swap Using Call by Reference


Algorithm: 1. Start. 2. Input two numbers. 3. Define a function: - Accept
references to two variables. - Use a temporary variable to swap values. 4. Call
the function and display results. 5. End.

You might also like