Friday 29 March 2019

CP: Total number of positive, negative and zero value in an array


Que:  Write a program to calculate a total number of positive, negative and zero value in an array using UDF.

Code: 

#include<stdio.h>

int main()

{
    int size,i,a[10];
    int positive=0, negative=0, zero=0;

    printf("\n Enter the size of array:  ");
    scanf("%d", &size);

    printf("\n Enter your array elements\n");

    for(i=0;i<size;i++)
    {
        scanf("%d", &a[i]);
    }

    for(i=0;i<size;i++)
    {
        if(a[i]>0)
        {
            positive++;
        }
        else if(a[i]<0)
        {
            negative++;
        }
        else
        {
            zero++;
        }

    }

    printf("\n total positive no: %d", positive);
    printf("\n total negative no: %d", negative);
    printf("\n total zero no: %d", zero);

    return 0;
}


Output: 











No comments:

Post a Comment

LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project

  LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project Dear All We will learn how to Connec...