# C Programming – HackerRank Solution | Stop at a point |

### (HackerRank) Write a Modular C Programming code to solve Stop at a point, Compute the sum of all positive values and print the sum and the number of values added.

Given a set of n integers containing both positive and negative values,

Compute the sum of all positive values and print the sum and the number of values added.

The program should terminate when the sum exceeds 999.

Input Format

A number n specify total numbers.

Next input n different numbers.

Constraints

n is positive number.

numbers can be positive or negative.

program should terminate when the sum exceeds 999.

Output Format

Sum of numbers.

Count of how many numbers were added.

Sample Input 0

```5
-10
-20
4
5
6
```

Sample Output 0

```Sum is 15.
```

Sample Input 1

```5
123
454
678
```

Sample Output 1

```Sum is 1255.
```

Sample Input 2

```-9
```

Sample Output 2

`Invalid input.`

CODE:

```#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

{
int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
void sum(int a,int n)
{
int i,sum=0,count=0;
for(i=0;i<n;i++) { if(a[i]>0)
{
sum=sum+a[i];
count++;
}
if(sum>999)
{
break;
}
}
printf("Sum is %d.\n",sum);
}

int main() {
int a,n;
scanf("%d",&n);
if(n>0)
{
sum(a,n);
}
else
printf("Invalid input.\n");
return 0;
}
```

OUTPUT

```Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

5
-10
-20
4
5
6

Sum is 15.
Expected Output

Sum is 15.
Interview```

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University 