Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 15
- //Return count and pass by reference the sum
- int CountSum(float arr[], int n, float* sum);
- //function for array input
- void read_arr(float arr[], int *n);
- //function to read the array values
- void write_arr(float a[], int *n);
- int main()
- {
- float arr[N];
- float totalSum = 0;
- int n;
- read_arr(arr, &n);
- int count = CountSum(arr, n, &totalSum);
- //write_arr(arr, &n);
- printf("Count: %d || Sum: %f \n", count, totalSum);
- return 0;
- }
- void read_arr(float a[], int *n)
- {
- int j;
- do
- {
- printf("\nVavedi razmernostta na masiva: ");
- scanf("%d", n);
- }
- while( *n < 1 || *n > N);
- for( j = 0; j < *n; j++ )
- {
- printf("array[%d]: ", j);
- scanf("%d", &a[j]);
- }
- }
- int CountSum(float arr[], int n, float* sum)
- {
- //Find all positive numbers and count of all 0 elements
- int i;
- int count = 0;
- for(i = 0; i < n; i++)
- {
- //If element is equal to 0, then increment the count
- if(arr[i] == 0)
- count++;
- //If the element is positive, add it to the sum
- if(arr[i] > 0)
- *sum += arr[i];
- }
- //Return the count
- return n;int j;
- printf("\n(");
- for( j = 0; j < n; j++ )
- {
- printf(" %d", a[j]);
- }
- printf(")\n");
- }
- void write_arr(float a[], int* n)
- {
- int j;
- printf("\n(");
- for( j = 0; j < n; j++ )
- {
- printf(" %d", a[j]);
- }
- printf(")\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement