#include <iostream.h>
#include <conio.h>
int funct(int a[], int n, char s = '+')
{
int sum = 0;
for(int i = 0; i< n ; i++ )
{
if(s == '+')
{
if(a[i] > 0 )
sum + = a[i];
}
else
{
if(a[i]<0)
sum+=a[i];
}
}
return sum;
}
void main()
{
int arr[20], dn;
cout<<"\n Enter dimension :";
cin>> dn;
for(int i = 0; i< dn ; i++)
{
cout<<"\n Enter any interger (positive / negetive )";
cin>> arr[i];
}
/* ... Sum of all positive integers in the array ... */
int s = funct( arr, dn);
/* .... Sum of all negative integers ..*/
int s2 = funct(arr, dn, '-');
cout<< "\n The sum of the positive integers : " << s;
cout<< "\n The sum of all negative integers : " << s2;
getch();
}
No comments:
Post a Comment