1) Write a program to enter the 20 numbers and
display the count of positive,
Share
1) Write a program to enter the 20 numbers and
display the count of positive,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Explanation:
/ C program to find the count of positive
// and negative integers in an array
#include <stdio.h>
// Function to find the count of
// positive integers in an array
int countPositiveNumbers(int* arr, int n)
{
int pos_count = 0;
int i;
for (i = 0; i < n; i++) {
if (arr[i] > 0)
pos_count++;
}
return pos_count;
}
/ / Driver program
int main()
{
int arr[] = { 2, -1, 5, 6, 0, -3 };
int n;
n = sizeof(arr) / sizeof(arr[0]);
printArray(arr, n);
printf("Count of Positive elements = %d\n",
countPositiveNumbers(arr, n));
return 0;
}