find sum and count of negative numbers from a set of n numbers c program
Answers
Answered by
0
Answer:
Jejdhdhiirirueueueue
Answered by
0
Program in C:
#include<stdio.h>
#include<conio.h>
int main()
{
int n , sum = 0 , count = 0 ;
printf("Enter numbers of elements : ");
scanf("%d" , &n);
int A[n];
printf("Enter elements in the array : \n");
for(int i = 0 ; i < n ; i++)
{
scanf("%d" , &A[i]);
}
for(int i = 0 ; i < n ; i++)
{
if(A[i] < 0)
{
sum = sum + A[i];
count++;
}
}
printf("Sum of negative numbers : %d \n" , sum);
printf("Count of negative numbers : %d \n" , count);
return 0;
}
Output:
Enter numbers of elements : 10
Enter elements in the array :
1
-2
3
-4
5
-6
7
-8
9
-10
Sum of negative numbers : -30
Count of negative numbers : 5
Similar questions
Computer Science,
2 months ago
Math,
2 months ago
Chemistry,
4 months ago
English,
4 months ago
English,
11 months ago
Environmental Sciences,
11 months ago