Setting Data Output in C

Asked

Viewed 66 times

0

I would like the output to show the tables of each operation side by side, and not one under the other (which is the form that is printing). Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{

  int i, num, rsoma, rsubtracao, rmultiplicacao;
  float rdivisao;

  i = 1;
  printf("Informe um numero inteiro: \n");
  scanf("%i", &num);
  printf("Adição\n\n");

  for ( i = 1; i < 11; i++)
  {
    rsoma = num + i;
    printf("%i + %i = %i\n", num, i, rsoma);
  }

  printf("\nSubtração\n\n");
  for ( i = 1; i < 11; i++)
  {
    rsubtracao = num - i;
    printf("%i - %i = %i\n", num, i, rsubtracao);
  }

  printf("\nMultiplicacao\n\n");
  for ( i = 1; i < 11; i++)
  {
    rmultiplicacao = num * i;
    printf("%i x %i = %i\n", num, i, rmultiplicacao);
  }

  printf("\nDivisao\n\n");
  for ( i = 1; i < 11; i++)
  {
    rdivisao = (float)num / i;
    printf("%i / %i = %.2f\n", num, i, rdivisao);
  }

 return 0;
}
  • Replace this printf n (new line) with a t (tab).

2 answers

1


Follow an example as requested, using \t (tabs):

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int i, num, rsoma, rsubtracao, rmultiplicacao;
    float rdivisao;

    i = 1;
    printf("Informe um numero inteiro: \n");
    scanf("%i", &num);
    printf("Adição\t\tSubtração\t\tMultiplicação\t\tDivisão\n\n");

    for ( i = 1; i < 11; i++)
    {
        rsoma = num + i;
        rsubtracao = num - i;
        rmultiplicacao = num * i;
        rdivisao = (float)num / i;
        printf("%i + %i = %i\t%i - %i = %i\t\t%i x %i = %i\t\t%i / %i = %.2f\n", num, i, rsoma, num, i, rsubtracao, num, i, rmultiplicacao, num, i, rdivisao);
    }

    return 0;
}

0

It would be something like this, in C it is difficult to give a "float" in the answer, but the solution is this
#include #include #include

int main()
{

  int i, num, rsoma, rsubtracao, rmultiplicacao;
  float rdivisao;

  i = 1;
  printf("Informe um numero inteiro: \n");
  scanf("%i", &num);
  printf("Adição\n\n");

  for ( i = 1; i < 11; i++)
  {
    rsoma = num + i;
    printf("%i + %i = %i\n", num, i, rsoma);
  }

  printf("\nSubtração\n\n");
  for ( i = 1; i < 11; i++)
  {
    rsubtracao = num - i;
    printf("%i - %i = %i\n", num, i, rsubtracao);
  }

  printf("\tMultiplicacao\n\n");
  for ( i = 1; i < 11; i++)
  {
    rmultiplicacao = num * i;
    printf("\t %i x %i = %i\n", num, i, rmultiplicacao);
  }

  printf("\t Divisao\n\n");
  for ( i = 1; i < 11; i++)
  {
    rdivisao = (float)num / i;
    printf("%i / %i = %.2f\n", num, i, rdivisao);
  }

 return 0;
}

Browser other questions tagged

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