count of positives numbers and the sum of negative numbers for the given array in c
Answers
Answered by
2
C Program to Count Positive and Negative Numbers in an Array
This program allows the user to enter the Size, and the row elements of One Dimensional Array. Next, we are using For Loop to iterate the array values and check for the Positive and Negative Number.
/* C Program to Count Positive and Negative Numbers in an Array */
#include<stdio.h>
int main()
{
int Size, i, a[10];
int Positive_Count = 0, Negative_Count = 0;
printf("\n Please Enter the Size of an Array : ");
scanf("%d", &Size);
printf("\nPlease Enter the Array Elements\n");
for(i = 0; i < Size; i++)
{
scanf("%d", &a[i]);
}
for(i = 0; i < Size; i ++)
{
if(a[i] >= 0)
{
Positive_Count++;
}
else
{
Negative_Count++;
}
}
printf("\n Total Number of Positive Numbers in this Array = %d ", Positive_Count);
printf("\n Total Number of Negative Numbers in this Array = %d ", Negative_Count);
return 0;
}
This program allows the user to enter the Size, and the row elements of One Dimensional Array. Next, we are using For Loop to iterate the array values and check for the Positive and Negative Number.
/* C Program to Count Positive and Negative Numbers in an Array */
#include<stdio.h>
int main()
{
int Size, i, a[10];
int Positive_Count = 0, Negative_Count = 0;
printf("\n Please Enter the Size of an Array : ");
scanf("%d", &Size);
printf("\nPlease Enter the Array Elements\n");
for(i = 0; i < Size; i++)
{
scanf("%d", &a[i]);
}
for(i = 0; i < Size; i ++)
{
if(a[i] >= 0)
{
Positive_Count++;
}
else
{
Negative_Count++;
}
}
printf("\n Total Number of Positive Numbers in this Array = %d ", Positive_Count);
printf("\n Total Number of Negative Numbers in this Array = %d ", Negative_Count);
return 0;
}
Similar questions