HackerRank C- Plus Minus




Complete the plusMinus function in the editor below. It should print out the ratio of positive, negative and zero items in the array, each on a separate line rounded to six decimals.

plusMinus has the following parameter(s):

arr: an array of integers



  1. #include<stdio.h>
  2. main()
  3. {
  4. int n,i;
  5. float b=0,c=0,d=0;
  6. float e,f,g;
  7. scanf("%d",&n);
  8. int a[n];
  9. for(i=0;i<n;i++)
  10. {
  11. scanf("%d",&a[i]);
  12. }
  13. for(i=0;i<n;i++)
  14. {
  15. if(a[i]<0)
  16. {
  17. b++;
  18. }
  19. if(a[i]>0)
  20. {
  21. c++;
  22. }
  23. if(a[i]==0)
  24. {
  25. d++;
  26. }
  27. }
  28. e=b/n;
  29. f=c/n;
  30. g=d/n;
  31. printf("%f\n%f\n%f",f,e,g);
  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