Home > Blockchain >  I have problem with my multiplication table,
I have problem with my multiplication table,

Time:11-26

So i have problem with multiplication by 0.[closed] This is my program:

#include <stdio.h>
int main() {
    int i,c,x,b,q,w,e,r,t,y,u;

    for (i = 1; i <=11; i  ) {
        printf("0 * %-2d = %-2d\n", i - 1, x=0), x = x * 0;
    }
    for (i = 1; i <= 11; i  )
    {
        printf("1 * %-2d = %-2d\n",i-1,x),x= 1 * i;
    }
    for (i = 1; i <= 11; i  )
    {
        printf("2 * %-2d = %-2d\n",i-1,b),b= 2 * i;
    }
    for (i = 1; i <= 11; i  )
    {
        printf("3 * %-2d = %-2d\n",i-1,c),c= 3 * i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("4 * %-2d = %-2d\n",i-1,q),q= 4 *i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("5 * %-2d = %-2d\n",i-1,w),w= 5 *i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("6 * %-2d = %-2d\n",i-1,e),e= 6 *i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("7 * %-2d = %-2d\n",i-1,r),r= 7 *i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("8 * %-2d = %-2d\n",i-1,t),t= 8 *i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("9 * %-2d = %-2d\n",i-1,y),y= 9 *i;
    }
    for (int i = 1; i <= 11; i  )
    {
        printf("10 * %-2d = %-2d\n",i-1,u),u= 10 *i;
    }

    return 0;
}

And i have problem with output by 0

  • 10 * 0 = 32599
  • 10 * 1 = 10
  • 10 * 2 = 20
  • All good with multiplication by 1,2,3... but with zero i have problem and don't know what to do

CodePudding user response:

Regarding @kaylum's comment about using a nested for loop, it looks like you're really just looking for something like this...

#include <stdio.h>
int main() {
  for (int x = 0; x <= 10; x  ) {
    for (int y = 1; y <= 10; y  ) {
      printf("%-2d * %-2d = %-2d\n", x, y, x * y);
    }
  }
  return 0;
}
  •  Tags:  
  • c
  • Related