You are on page 1of 9

1. To calculate the area of triangle using the formula area = (s(s-a) (s-b)(s-c))1/2 where s= (a+b+c)/2.

Alogorithm:

Step1: Start

Step 2: Input a,b,c

Step 3: Calculate s = (a + b + c ) / 2

Step 4: Calculate area = sqrt( s*(s-a)*(s-b)*(s-c))

Step 5: print "Area of Triangle=", area

Step 6: End
2. To find the Largest Number (integer) and Smallest among three numbers (integers) using ternary
operator.
Algorithm : Largest Number
Step 1 : Start.
Start 2 : Input A, B, C.
Start 3 : if A>B go to step 4 else goto step 5
Start 4 : if A > C then print A is Largest Number and goto step 7 else go to step 6
Start 5 : if B>C then print B is Largest Number and goto step 7 else goto step 6 .
Start 6 : print C is Largest Number
Start 7 : Stop.

Algorithm : Smallest Number


Step 1 : Start.
Start 2 : Input A, B, C.
Start 3 : if A<B go to step 4 else goto step 5
Start 4 : if A < C then print A is Smallest Number and goto step 7 else go to step 6
Start 5 : if B<C then print B is Smallest Number and goto step 7 else goto step 6 .
Start 6 : print C is Smallest Number
Start 7 : Stop.
Write flow chart for smallest number in your own by changing comparision

3. Design and develop a flowchart or an algorithm that takes three coefficients (a, b, and c) of a quadratic
equation (ax2+bx+c=0) as input and computes all possible roots. An equation is quadratic only if a is non
zero. If a is zero and b is non zero in the above equation then it becomes a linear equation (bx + c = 0).If a
and b are zeros then the it becomes a constant equation. Implement a C program for the developed
flowchart/algorithm and execute the same to output the possible roots for a given set of coefficients with
appropriate messages.
Algorithm:
Step 1: Start

Step 2: Input a,b,c,d,root1,root2;

Step 3: if a==0 goto step 4 else goto step 5.

Step 4: if b==0 print Linear Equation and goto step 9 else print Constant Equation and goto 9.

Step 5: Calculate d=b*b-4*a*c.

Step 6: if d=0 calculate root1=root2=-b/(2*a) and print roots are equal and goto step 9 else goto step 7.

Step 7:if d>0 calculate root1=(-b+sqrt(d))/(2*a), root2=(-b-sqrt(d))/(2*a) and print roots are real and different
and goto step 9 else goto step 8.

Step 8: Print roots are not real and imaginary.

Step 9: Stop
4. Read two integer operands and one operator form the user, perform the operation and then print the
result. (Consider the operators +,-,*, /, % and use Switch Statement)
Algorithm:
Step 1: Start
Step 2: Input a,b,operator.
Step 3: If expression matches with ‘+’ print a+b and goto Step 9 else goto Step 4
Step 4: If expression matches with ‘-’ print a-b and goto Step 9 else goto Step 5
Step 5: If expression matches with ‘*’ print a*b and goto Step 9 else goto Step 6
Step 6: If expression matches with ‘/’ print a/b and goto Step 9 else goto Step 7
Step 7: If expression matches with ‘%’ print a%b and goto Step 9 else goto Step 8
Step 8: print Invalid operator.
Step 9:Stop
5. Write a C program to find the sum of n natural numbers and sum of squares of n natural numbers.
Algorithm:1
Step 1 : Start
Step 2 : Assign sum=0 and i=0
Step 3 : Read limit of number , n
Step 4 : Repeat steps 5 to 6 until i=n reached
Step 5 : Compute sum=sum+i
Step 6 : Compute i=i+1
Step 7 : Print sum
Step 8 : Stop
Algorithm:2
Step 1 : Start
Step 2 : Assign sum=0 and i=0
Step 3 : Read limit of number , n
Step 4 : Repeat steps 5 to 6 until i=n reached
Step 5 : Compute sum=sum+(i*i)
Step 6 : Compute i=i+1
Step 7 : Print sum
Step 8 : Stop

Write flow chart in your own for sum of squares by changing sum=sum+(i*i)

6. Read a number from the user input, print all the prime numbers up to that number and print their sum.
Algorithm:
STEP 1: START

STEP 2: Input i,j,isPrime,number,sum;

STEP 3: REPEAT STEP 4 to STEP 11 until i<=number

STEP 4: SET j= 1
STEP 5: SET isPrime = 0

STEP 6: REPEAT STEP7 to STEP 8 UNTIL j<=i

STEP 7: if i%j = = 0 then isPrime=1;

STEP 8: j = j + 1

STEP 9: if isPrime = 1 then print i and calculate sum=sum+i

STEP 10: n = n +1

STEP 11: i = i +1

STEP 12: print sum.

STEP 13: END
7.Write a C program that accepts 4 integers p, q, r, s from the user where r and s are positive and p is even.
If q is greater than r and s is greater than p and if the sum of r and s is greater than the sum of p and q print
"Correct values", otherwise print "Wrong values".
Algorithm:
Step 1: Start
Step 2: Read p,q,r,s values.
Step 3: if r>0 and s>0 and p%2==0 goto step 4 and else goto Step 7.
Step 4: if q>r and s>p goto step 5 else goto Step 7.
Step 5: if r+s > p+q goto step 6 else goto Step 7
Step 6: Print Correct values goto step 8.
Step 7: Print Wrong values.
Step 8:Stop

You might also like