Thursday 28 December 2023

Solution to Maths Problem no 2

Here is one way to work it out, which will only make sense if you can program in C:

andrew@ASUS-Laptop:~/Maths_Problems$ cat multiply.c
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

void para_a (void);
void para_b (void);
void para_c (void);
void para_d (void);

/* Global variables. */

int a;
int b;
int c;
int d;

int main ()
{
para_a();
}
void para_a ()
{
for (a = 1; a <= 9; a++) para_b();
}
void para_b ()
{
for (b = 0; b <= 9; b++) para_c();
}
void para_c ()
{
for (c = 0; c <= 9; c++) para_d();
}
void para_d ()
{
for (d = 0; d <= 9; d++)
  {
  if ((a!=b)  && (a!=c) && (a!=d) && (b!=c) && (b!=d) && (c!=d))
    {
    if (9*(1000*a+100*b+10*c+d) == 1000*d+100*c+10*b+a)
      printf("%d %d %d %d\n", a, b, c, d);
    }
  }
}
andrew@ASUS-Laptop:~/Maths_Problems$ cc -o multiply multiply.c
andrew@ASUS-Laptop:~/Maths_Problems$ ./multiply
1 0 8 9
andrew@ASUS-Laptop:~/Maths_Problems$

No comments:

Post a Comment