/****************************************** * Section : 15 * Machine No. : N * Roll No. : 19CS100XY * Name : Aritra Hazra * Assignment No : 3B * Description : School-book Multiplication ******************************************/ #include int main( ) { unsigned long long int multiplicand, multiplier, i, j, k, l, intrimResult, digitResult, carryResult, stepResult, finalResult, m1, m2, unit1, unit2; /* taking two integer inputs */ printf("Enter Multiplicand: "); scanf("%llu", &multiplicand); printf("Enter Multiplier: "); scanf("%llu", &multiplier); printf("\n++ School-book Multiplication Procedure ++\n"); printf("%32llu\n", multiplicand); printf("%32llu\n", multiplier); printf("---------------------------------\n"); m2 = multiplier; finalResult = 0; l = 1; /* looping for each digit of multiplier */ while (m2 > 0) { m1 = multiplicand; unit2 = m2 % 10; /* present LSB of multiplier */ intrimResult = 0; carryResult = 0; stepResult = 0; k = 1; /* looping for each digit of multiplicand */ while (m1 > 0) { unit1 = m1 % 10; /* present LSB of multiplicand */ /* intermediate result generation: digit and carry brakeup */ intrimResult = (unit1 * unit2 + carryResult); digitResult = intrimResult % 10; carryResult = intrimResult / 10; stepResult = stepResult + k * digitResult; /* result obtained each step */ k = 10 * k; m1 = m1 / 10; } stepResult = stepResult + k * carryResult; /* adjusting the final carry in each step */ printf("%32llu\n", stepResult * l); m2 = m2 / 10; finalResult = finalResult + l * stepResult; /* final summed up step results */ l = 10 * l; } printf("---------------------------------\n"); printf("%32llu\n", finalResult); return 0; }