Input:
6
-4 3 -9 0 4 1
Expected output:
0.500000
0.333333
0.166667
My output:
0.000000
0.000000
0.000000
Code explanation:
1)User enters the number of inputs
2)User enters numbers
3)Code displays percentage of positive / negative / zero numbers
What am I doing wrong?
#include<stdio.h>
int main()
{
int counter=0;
int howmany;
scanf("%d",&howmany);
int clone=howmany;
int numbers[howmany];
int zero=0, positive=0, negative=0;
while(howmany>0)
{
scanf("%d",&numbers[counter]);
if(numbers[counter]>0)
{
positive++;
}
else if(numbers[counter]<0)
{
negative++;
}
else if(numbers[counter]==0)
{
zero++;
}
counter++;
howmany--;
}
double a=positive/clone;
double b=negative/clone;
double c=zero/clone;
printf("%lf\n%lf\n%lf",a, b, c);
return 0;
}