Skip to content

Instantly share code, notes, and snippets.

@fenske
Last active December 24, 2019 12:52
Show Gist options
  • Select an option

  • Save fenske/d44a95978e7bdb226e38092ebbb37803 to your computer and use it in GitHub Desktop.

Select an option

Save fenske/d44a95978e7bdb226e38092ebbb37803 to your computer and use it in GitHub Desktop.
#include <iostream>
#define N 5
using namespace std;
void calc(int* arr, int* sum, int* cnt)
{
int i, k = 0, s = 0;
for (i = 0; i < N; i++)
{
if (arr[i] < 0) {
s += arr[i];
k++;
}
}
*sum = s;
*cnt = k;
}
void main()
{
int arr[N], i;
for (i = 0; i < N; i++)
{
cout << "arr[" << i << "] = ";
cin >> arr[i];
}
int sum, cnt;
calc(arr, &sum, &cnt);
cout << "sum = " << sum << endl;
cout << "count = " << cnt << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment