Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Enter an integer array a and find the sum of all positive numbers in the array. Requirements: Write the following functions: int positive_sum (?
Enter an integer array a and find the sum of all positive numbers in the array. Requirements: Write the following functions: int positive_sum (?
Hello, the program has been written. Take the number 10 as an example:

# include & ltstdio.h & gt

int positive_sum(int *a,int n)

{

int i,sum = 0;

for(I = 0; I & ltn;; i++)

if(*(a+I)& gt; 0)

sum+= *(a+I);

Returns the sum;

}

int main()

{

int a[ 10],I,sum

for(I = 0; I< 10; i++)

scanf("%d ",& ampa[I]);

Sum = positive number _sum(a,10);

printf("%d\n ",sum);

}

Adopt it ~