How do I stop organizing the table in while?

2

How do I stop organizing this table? Sum, subtraction and multiplication respectively?

#include <stdio.h>

int main (){
int i=0, num=0;

printf ("Digite um n£mero: ");
scanf ("%d",&num);

printf ("\n");

while (i<=9){
    i++;
    printf ("%d + %d = %d\n", i, num, num+i);

    printf ("%d - %d = %d\n", i, num, i-num);

    printf ("%d X %d = %d\n", i, num, num*i);
}
}
    
asked by anonymous 21.10.2017 / 18:08

1 answer

7

Just replace '\ n's' from the first and second printf with' \ t's, this way it will not do the line break, which in the case is' \ n ', and still give a tab, in case o \ t , (equivalent to four spaces).

#include <stdio.h>

int main ()
{
    int i=0, num=0;

    printf ("Digite um n£mero: ");
    scanf ("%d",&num);

    printf ("\n");

    while ( i <= 9 )
    {
        i++;
        printf ("%d + %d = %d\t", i, num, num+i);

        printf ("%d - %d = %d\t", i, num, i-num);

        printf ("%d X %d = %d\n", i, num, num*i);
    }

    return 0;
}

In this case the output will look like this:

otherway:

#include<stdio.h>#include<locale.h>intmain(){inti=0,num=0;setlocale(LC_ALL,"");

    printf ("Digite um número: ");
    scanf (" %d", &num);

    printf ("\nAdição:\n");
    for ( i = 0; i <= 9; i++ )
        printf ("%d + %d = %d\n", i, num, num+i);

    printf ("\nSubtração:\n");
    for ( i = 0; i <= 9; i++ )
        printf ("%d - %d = %d\n", i, num, i-num);

    printf ("\nMultiplicação\n");
    for ( i = 0; i <= 9; i++ )
        printf ("%d X %d = %d\n", i, num, num*i);

    return 0;
}

In this way the output will be sequential, I added the locale.h library to use accent, the command setlocale(LC_ALL, ""); is the command that allows the BR accents to be used, the image of this output is this:

    
21.10.2017 / 18:17