Is giving error in the matrix using the while loop

Asked

Viewed 490 times

0

How do I make the matrix be rotated with the while loop? My teacher wants the matrix to be displayed with the while loop I only know how to do with the for loop. Follow example with errors of how I did:

#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

}

  • which error is occurring?

  • 2

    C# and C are two things well different.

  • I know :/ I put two tags to draw more attention, even.

  • @Dotnet actually doesn’t work as expected.

1 answer

2


Is this it? I just changed the size of the matrix 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;
}
  • 1

    this code just prints the matrix. the rest is with vc :-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.