You are giving error in the array using the while loop

0

How do I make the array to be rotated with the while loop? My teacher wants the array to be displayed with the while loop I just know how to do with the for loop. Here is an example of how I did it:

#include<stdio.h>

void main(){
int inteiros[5][5];
int i = 0, j = 0;

//copia do teclado

while(*inteiros != NULL){       
        scanf("%d", &inteiros[i][j]);

        i++;
        j++;
}




 //imprime como formato de matriz

while(*inteiros != NULL){       


        printf("%d", inteiros[i][j]);

        i++;
        j++;
        printf ("\n"); 

}

printf("\n\n");

    //matriz diagonal principal
while(*inteiros != NULL){       
        scanf("%d", &inteiros[i][j]);

            if(i == j){
                printf( "[%d][%d] : %d. ", i, j, inteiros[i][j] );
            }
        i++;
        j++;
    }


printf("\n");
//matriz inversa

}

    
asked by anonymous 01.06.2016 / 17:15

1 answer

2

Would this be? I just changed the size of the array to 2x2 for ease. Make sure you understand!

#include <stdio.h>

int main(int argc, const char * argv[]) {

    int inteiros[2][2];

    inteiros[0][0] = 1;
    inteiros[0][1] = 2;
    inteiros[1][0] = 3;
    inteiros[1][1] = 4;

    int i = 0;
    int j = 0;
    while (i<2) {
        j = 0;
        while(j<2){
            printf("%d\n",inteiros[i][j]);
            j++;
        }
        i++;
    }

    return 0;
}
    
01.06.2016 / 17:27