joliveramu / count_sum

This program counts the positive integer and sums up all the negative integers in an array

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

count_sum

This program counts the positive integer and sums up all the negative integers in an array. I took this program out from my internship examination. I find it good as it's more of array manipulations.

PS. I made a mistake during the exam as I overlook the question, I thought that I have to sum up both positive and negative integers on the other side. The Tech HR laugh on my mistake but the approach is good. I just did overlook the question hehe

What I did?

These conditions will solve it. Let's assume I already have the array, a variable that contains the sum of negative integers and the count variable for the positive integers.

*If the element is greater than 0, increment the count variable by 1 *If the element is less than 0, add the element to the sum variable that holds all the sum of negative integers

That solves it.

Tips And Tricks that made it done

  • Create a variable sum (for negative integers)
  • Create a variable count (for positive integers)
  • if the element is > 0, increment count by 1
  • if the element is < 0, add the element to the sum variable

That's it and Happy Coding!

About

This program counts the positive integer and sums up all the negative integers in an array


Languages

Language:Java 18.3%Language:C# 17.8%Language:C++ 17.1%Language:C 14.9%Language:PHP 12.4%Language:JavaScript 9.8%Language:Python 9.8%