Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What will be the correct output for the given code snippet?

  1. class maths
  2. {
  3. int fact(int n)
  4. {
  5. int result;
  6. if (n == 1)
  7. return 1;
  8. result = fact(n - 1) * n;
  9. return result;
  10. }
  11. }
  12. class Output
  13. {
  14. static void main(String args[])
  15. {
  16. maths obj = new maths() ;
  17. Console.WriteLine(obj.fact(4)*(3));
  18. }
  19. }

a)b)c)d)

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/21
Shilpa Kotian
by Shilpa Kotian , Software engineer , Reliable sol

72 is the answer

72 =fact(4)*3

fact(4) =fact(3) *4

fact(3)=fact(2)*3

fact(2)=fact(1)*2

fact(1)= 1 because if n==1 then return 1

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.