Number of Profitable Days
Coding Problem Keys
Number of Profitable Days
Problem Statement
The e-commerce company "TodaysApparel" has a list of sales values of N days. Some days the company made a profit, represented as a positive sales value. Other days the company incurred a loss, represented as a negative sales value. The company wishes to know the number of profitable days in the list.Write a algorithm to help the company know the number of profitable days in the list.
Input Format
The first line of input consists of an integer - numDays representing the number of days (N).The second line of input consists of N space-separated integers - sales[0], sales[1] .............. sales[N-1] representing the sales values of N days respectively.
Output Format
Print an integer representing the number of days the company made a profit.
Example Input/Output 1
Input
723 -7 13 -34 56 43 -12
Output
4
Explanation
The number of positive sales values in the list is 4. Hence the output is 4.
Example Input/Output 2
Input
812 45 -78 22 16 2 14 -23
Output
6
Solution
Programming Language: Python 3 Language
n=int(input())
l=list(map(int,input().split()))
c=0
for i in l:
if i>0:
c+=1
print(c)
# Published By PKJCODERS
Programming Language: C Language
#include <stdio.h>
int main() {
int N,c=0;
scanf("%d",&N);
int arr[N];
for(int i=0;i<N;i++)
scanf("%d",&arr[i]);
for(int i=0;i<N;i++)
if(arr[i]>0)
c++;
printf("%d",c);
}
// Published By PKJCODERS
Programming Language: C++ Language
#include <iostream>
using namespace std;
int main() {
int N,c=0;
cin>>N;
int arr[N];
for(int i=0;i<N;i++)
cin>>arr[i];
for(int i=0;i<N;i++)
if(arr[i]>0)
c++;
cout<<c;
}
// Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments