HackerRank C- Mini-Max Sum




Complete the miniMaxSum function in the editor below. It should print two space-separated integers on one line: the minimum sum and the maximum sum 4 of 5 of elements.

miniMaxSum has the following parameter(s):

arr: an array of 5 integers



  1. #include<stdio.h>
  2. int main()
  3. {
  4. long long int min=0,max=0,count=0,temp=0,minsum=0,maxsum=0,c=0;
  5. long long int a[5];
  6. for(int i=0;i<5;i++)
  7. {
  8. scanf("%lld",&a[i])'
  9. }
  10. for(int i=0;i<5;i++)
  11. {
  12. for(int j=0;j<5;j++)
  13. {
  14. if(a[i]<a[j])
  15. {
  16. temp=a[i];
  17. a[i]=a[j];
  18. a[j]=temp;
  19. }
  20. }
  21. }
  22. min=a[0];
  23. max=a[4];
  24. for(int i=0;i<5;i++)
  25. {
  26. if(c==0&&a[i]!=a[i+1])
  27. {
  28. if(a[i]!=max)
  29. {
  30. minsum=minsum+a[i];
  31. }
  32. if(a[i]!=min)
  33. {
  34. maxsum=maxsum+a[i];
  35. }
  36. }
  37. if(a[i]==a[i+1])
  38. {
  39. minsum=minsum+a[i];
  40. maxsum=maxsum+a[i];
  41. c=1;
  42. }
  43. }
  44. printf("%lld %lld ",minsum,maxsum);
  45. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






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