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

C Program Algorithm

Uploaded by

IT sacwc
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C Program Algorithm

Uploaded by

IT sacwc
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.Largest and smallest of three numbers.

1.Start the program.

2.Ask the user to enter three integer values.

3Read the three integer values in n1, n2, and n3 (integer variables).

4.Check if n1 is greater than n2 and n3.If true, then print ‘n1’ as the greatest number.

5.If false, then check if n2 is greater than n3.

If true, then print ‘n2’ as the greatest number.


If false, then print ‘n3’ as the greatest number.

6.Chech if n1 is smaller than n2 and n3.

If true, then print ‘n1’ as the smallest number.

7.If false ,then check if n2 is smaller than n3.

If true, then print ‘n2’ as the smallest number.


If false, then print ‘n3’ as the smallest number.

8.Stop the program.

2.Armstrong number

1) Start the program.


2) Declare Variable sum, temp, n.
3) Read n from User.
4) Initialize Variable sum=0 and temp=n.
5) Repeat Until num>0
sum=sum + cube of last digit i.e [(n%10)*(n%10)*(n%10)]
n=n/10
6) IF temp==sum
Print "Armstrong Number"
ELSE
Print "Not Armstrong Number"
7) Stop the program.

3.Quadratic equation using switch

1) Start the program.


2) Input coefficients of quadratic equation. Store it in some variable say a, b and c.
3) Find discriminant of given equation using formula i.e. discriminant = (b * b) - (4 * a * c).
4) Compute the roots based on the nature of discriminant. Switch the value of
switch(discriminant > 0).
5) The expression (discriminant > 0) can have two possible cases i.e. case 0 and case 1.
6) For case 1 means discriminant is positive. Apply formula root1 = (-b + sqrt(discriminant)) /
(2*a); to compute root1 and root2 = (-b - sqrt(discriminant)) / (2*a); to compute root2.
7) For case 0 means discriminant is either negative or zero. There exist one more condition to
check i.e. switch(discriminant < 0).
8) Inside case 0 switch the expression switch(discriminant < 0).
9) For the above nested switch there are two possible cases. Which is case 1 and case 0. case 1
means discriminant is negative. Whereas case 0 means discriminant is zero.
10) Apply the formula to compute roots for both the inner cases.
11) Stop the program.

4. Ascending and Decending order of numbers using arrays.

1. Start the program.


2. Declare and initialize an array.
3. Loop through the array and select an element.
4. The inner loop will be used to compare the selected element from the outer loop with the
rest of the elements of the array.
5. If any element is less than the selected element then swap the values.
6. Continue this process till entire array is sorted in ascending order.
7. Otherwise If any element is greater than the selected element then swap the values.
8. Continue this process till entire list is sorted in descending order.
9. Print the elements.
10. Stop the program.

5. Sorting of names in alphabetical order.

1. Start the program.


2. Create an array and initialize with the values.
3. For loop from i=0 to i<size_of_array.
4. Nest another for loop from j=0 to j<size_of_array-i-1.
5. Check if(strcmp(array[j], array[j+1]) > 0).
6. If yes, then swap(array[j], array[j+1]).
7. End nested loop.
8. End external loop.
9. Output sorted array
10. Stop the program.
8.Finding factorial of a number using recursive function

1. Start the program.

2. Declare the integer variables num,result.

3. Read a number and store it in a variable num.

4. Call factorial(n) function and store the result in a variable result.

5. If n==1 then return 1

6. Else return n*factorial(n-1) value

7. Print the variable result .

8. Stop the program.

9.Generating fibbonacci series using recursive function.

Algorithm.

1.Start the program.

2. Input the non-negative integer ‘n’.

3. check the condition If (n==o || n==1) then return n,else return fib(n-1)+fib(n-2).

4. Print, nth Fibonacci number.

5. Stop the program.

You might also like