Plus Minus solution

Problem discussion

          Plus Minus has N number of elements in an Array. You have to calculate the ratio of positive, negative and zero items in the Array. To calculate the ratio you need to find out the total items of positive, negative and zero. For that apply Array[index] > 0 to find positive numbers and Array[index] < 0 to find negative numbers. After that divide by total number. Such as:

Positive ratio: Total positive number ÷ Total number
Positive ratio: Total negative number ÷ Total number
Positive ratio: Total number of zero ÷ Total number

          Hopefully, you understand the problem. Now try to solve the problem. You can get help from the below code.

Source code

Before seeing the source code ensure that you have tried hard most!!! 

 

#include<cstdio>
#include<cstdlib>

int main()
{
    int n;

    scanf("%d",&n);

    int data;

    int Plus = 0;
    int Minus = 0;
    int Zero = 0;


    for(int index = 0; index < n; index++)
    {
        scanf("%d", &data);
        if(data > 0)
            Plus++;
        else if(data < 0)
            Minus++;
        else
            Zero++;
    }

    printf("%f\n",(float)Plus/n);
    printf("%f\n",(float)Minus/n);
    printf("%f\n",(float)Zero/n);


    return 0;
}
Be with us, stay happy. Please do your precious comment and give an opportunity to improve us.

Happy coding.

Leave a comment

Website Powered by WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started