Space between matrix number

Asked

Viewed 88 times

0

Good evening, I’m new to the site and beginner in C Language ,I know only the basics for now,I have a question that I’m struggling if someone knows how to solve would be grateful. I’m taking the Matrize and the Matrizf and adding to each other , it all worked out in the account , the problem is that I can not leave space between a number and another, instead of being like this : 3 7 5 gets together like this 375, someone knows how to solve? I use Visual Studio 2019.

#include<stdio.h>

int main()
{

    int i, j;
    int matrizE[2][3] = { {0, 3, 6},{8, 4, 2} };
    float matrizF[2][3] = { {2.2, 1.6, 2.6},{0.4, 3.1, 6.4} };
    float resultado[2][3];

    for (i = 0; i < 2; i++) {
        for (j = 0; j < 3; j++)
            resultado[i][j] = matrizE[i][j] + matrizF[i][j];
    }

    printf("\n***Primeira matriz*** \n");
    for (i = 0; i < 2; ++i) {
        for (j = 0; j < 3; ++j)
            printf("%d", matrizE[i][j]);
        printf("\n");
    }

    printf("\n***Segunda matriz*** \n");
    for (i = 0; i < 2; ++i) {
        for (j = 0; j < 3; ++j)
            printf("%.1f", matrizF[i][j]);
        printf("\n");
    }
    printf("\n***Resultado da soma*** \n");
    for (i = 0; i < 2; ++i) {
        for (j = 0; j < 3; ++j)
            printf("%.1f", resultado[i][j]);
        printf("\n");
    }



return 0;
}

1 answer

2


Just put a space after the %d and others of the type inside the quotes of the printf.

printf("%d ", .....);
  • thanks , seeing now is very simple , but did not know hehe, obg.

Browser other questions tagged

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