// Q(5) - (25 marks)
// Write C++ program of the following:
// 1- (sepN) is a function that accepts two parameters:
// * an array (arr) of integer values.
// * its (size)
// * returns nymber of the negative values in an array (arr).
// 2- main function that:
// * defines an array named (myArr) to store 20 integer values.
// * promots the user to fill the array (myArr) from the keyboard.
// * calls the function (sepN) to count the number of negative
// values in the array (myArr)
// * displays the number of negative values returned by function (sepN).
// Sample Input/Output:
// Enter 20 array elements:
// 1 2 3 4 5 6 -7 -8 -9 -10 -11 12 13 14 15 16 17 18 19 20
// The number of negative values in array is= 5
int sepN ( int arr[], int s )
{
int n=0;
for (int j=0; j<s; j++)
if ( arr[j]<0 )
++n;
return n;
}
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
int myArr[20];
cout<<" Enter 20 array elements:"<<endl;
for (int i=0; i<20; i++)
cin>> myArr[i];
cout<< "The number of negative values in array is="<< sepN(myArr,20);
system("PAUSE");
return 0;
}
#include <cstdlib>
#include <iostream>
usingnamespace std;
int sepN ( int arr[], int s )
{
int n=0;
for (int j=0; j<s; j++) {
if ( arr[j]<0 )
++n;
}
return n;
}
int main()
{
int myArr[20];
cout<<" Enter 20 array elements:"<<endl;
for (int i=0; i<20; i++)
cin>> myArr[i];
cout << "The number of negative values in array is=" << sepN(myArr,20);
return 0;
}