1.

Write an algorithm to find the sum of n natural numbers and average?Step 1 : Start Step 2 : Set i 1, S 0 Step 3 : Read a number and set to n Step 4 : Computer i and n if i>n then go to step 7. Step 5 : Set S <— S+ iStep 6 : i <— i+1 go to step 4 Step 7 : avg 4<— S/n Step 8 : Print “Sum = S and average = avg” Step 9 : Stop numbers.

Answer»

step 1 : Start 

Step 2 : Read 3 numbers and store in A,B,C 

Step 3 : Compare A and B. lfA>B then go to Step 6 

Step 4 : Compare B and C if C>B then go to Step 8 

Step 5 : print “B is largest” go to Step 9 

Step 6 : Compare A and C if Q>A then go to Step 8 

Step 7 : Print” A is largest” go to Step 9 

Step 8 : Print “C is largest” 

Step 9 : Stop



Discussion

No Comment Found

Related InterviewSolutions