1.

Write an algorithm to find the sum of n natural numbers and average?

Answer»
  • 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 + i 
  • Step 6: i ← i + 1 go to step 4
  • Step 7: avg ← S/n 
  • Step 8: Print “Sum = S and average = avg” 
  • Step 9: Stop 


Discussion

No Comment Found

Related InterviewSolutions