dimanche 18 novembre 2018

Read and print only positive array indexes

The question i have is similiar to some questions answered, but the answer for this in particuliar wasnt in there. Here is my code

    int main()
{   int i,j,k,sorted;
    int A[4][4];
    int C[16];
    int positive = 0;

    for(i=0;i<4;i++)
    {
        for(j = 0; j<4; j++)
        {
            printf("A[%d][%d]: ", i,j);
            scanf("%d", &A[i][j]);

            if(A[i][j]>0){
                C[positive] = A[i][j];
                printf("C = %d\n");         
                positive++;
            }       
        }
    }
    for(j=0;j<4;j++)
    {
        printf("%d  ", A[positive]);
    }
    printf("\n");
    //printf("Your positive numbers are: ", positive);

    printf("\n");
    system("pause");
    return 0;

}

I want to check if the input is negative and add it to the 1D array only then. The question is how do i do that? Any ideas?

Thanks in ad

Aucun commentaire:

Enregistrer un commentaire