Contar numeros negativos e positivos num array usando ponteiros

#include <stdio.h>
#include <stdlib.h>

#define TAM 10

int  contarN(int *r, int s, int *pP, int *pN)
{
    int i;

    for(i=0; i < s; i++)
    {
        if(*(r+i)>=0)
        {
            *pP=(*pP)+1;
        }else
        {
            *pN=*pN+1;
        }
    }
    printf("%d - %d \n", *pP, *pN);
    return 0;
}


int main()
{
    int tab1[TAM]= {0,12,2,333,-4,54,6,77,88,-99};
    int *a=tab1, numP=0, numN=0;

    contarN(a, TAM, &numP, &numN);
    return 0;
}

Tags : , ,

0 thoughts on “Contar numeros negativos e positivos num array usando ponteiros”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.