c++ program to print first odd digit number in an array code example

Example 1: Print Odd Even Negative Integer Count

#include<stdio.h>
int main()
{
int n,i,e=0,o=0,ne=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
if(a[i]<0) ne++;
else if(a[i]%2==0&&a[i]>=0) e++;
else o++;
}
    printf("%d %d %d",o,e,ne);

}

Example 2: return odd numbers c++

#include<iostream>
int copyOdd (int A[], int sizeA, int B[]);
int main ()
{
    int arr [] {1,2,3,4,5,6,7,8,9,10};
    int Odd [5] {0,0,0,0,0};
    copyOdd(arr,9,Odd);
    

    for(int i = 0 ; i < 5; ++i)
    {
        std::cout<<Odd[i]<<' ';
    }
    std::cout<<std::endl;

    return 0 ;

}

int copyOdd (int A[], int sizeA, int B[])
{   
    int j {0};
    B [5];
    for(int i  = 0 ; i < sizeA ; ++i)
    {
        if(A[i]%2 == 1)
            B[j++] = A[i];
            
    }

    return B[5];
}

Tags:

C Example