GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Zoho problem(please help stuck in my logic)

Given an array and a threshold value find the o/p

eg) i/p {5,8,10,13,6,2};threshold = 3;
      o/p  count = 17
      explanation:
Number	parts	            counts
5	            {3,2}                 2
8                      {3,3,2}              3
10                    {3,3,3,1}           4
13                    {3,3,3,3,1}        5
6                      {3,3}                 2
2                      {2}                    1 
asked Jul 5, 2016 by Ram

1 Answer

#include <stdio.h>

int main(void) {

    int nArray[] = {5, 8, 10, 13, 6, 2}, nthreshold = 3, i = 0;

    int temp, count =0;    
    for ( i =0; i < 6; i++)
    {
            temp = nArray[i]%3;
            
            if ( temp != 0)
                temp = (nArray[i] /3 ) +1;
            else
                temp = nArray[i]/3;
            
            count = count + temp;
    }
    printf ("Final count : %d", count);
    return 0;
}

answered Jul 5, 2016 by jeyamb
...