HackerRank C++ Functions




Print the greatest of the four integers.
PS: I/O will be automatically handled.



  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. int max_of_four(int a, int b, int c, int d)
  5. {
  6. if(a>b&&a>c&&a>d)
  7. {
  8. cout<<a;
  9. return(a);
  10. }
  11. else if(b>a&&b>c&&b>d)
  12. {
  13. cout<<b;
  14. return(b);
  15. }
  16. else if(c>b&&c>a&&c>d)
  17. {
  18. cout<<c;
  19. return(c);
  20. }
  21. else
  22. {
  23. cout<<d;
  24. return(d);
  25. }
  26. }
  27. int main()
  28. {
  29. int a, b, c, d,max;
  30. cin>>a>>b>>c>>d;
  31. max=max_of_four(a,b,c,d);
  32. }




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube