• + 1 comment

    solution of this code in c...

    int main() {
      int n, a[10000] = {0}, i = 0, carry, cpy, len, func, neww;
      scanf("%d", &n);
      if(n==1)
      printf("1");
      else
      {
      cpy = n;
      while (cpy != 0) {
        a[i] = cpy % 10;
        cpy = cpy / 10;
        i++;
      }
      while (n != 1) {
        for (len = 0; len < i; len++);
        n--;
        i = 0;
        carry = 0;
        for (i = 0; i <= len + 1; i++) {
          func = n * a[i] + carry;
          a[i] = func % 10;
          carry = func / 10;
        }
      }
      for (i = len; i >= 0; i--)
        if (a[i] != 0) {
          neww = i;
          break;
        }
      for (i = neww; i >= 0; i--)
        printf("%d", a[i]);
      }
    }
    

    logic : - suppose you're asked to multiply 25 with 24..

    what toddlers do..

    25
    

    * 24

    100

    50 *


    600

    what we do... 5*24=120, 0 stays, carry 12... then 2*24+12=60.. hence 600. this method is called supercarry. Take an array, use this supercarry method and for every i, print a digit in array[i]. then print the anti-array. If there are extra zeroes in front of the answer, remove them by using..

    for (i = len; i >= 0; i--) if (a[i] != 0) { neww = i; break; } for (i = neww; i >= 0; i--) printf("%d", a[i]);

    how your multiplication goes..

    n=25.

    52 006 00831 006303

    etc..

    when you print the anti-array

    the number prints without any problem...