/*********************************************** * Section : 15 * Machine No. : N * Roll No. : 19CS100XY * Name : Aritra Hazra * Assignment No : 3A * Description : Multiplication Table Generation ***********************************************/ #include int main( ) { unsigned int n, m, base, i, j, k, result, convResult, tempResult; /* taking input parameters for multiplication table */ printf("Enter Number of Multiplication Table Entries: "); scanf("%u", &n); printf("Enter Multiplication Depth: "); scanf("%u", &m); printf("Enter Base Value (within range [2-10]): "); scanf("%u", &base); /* creating multiplication table by direct multiplication method */ printf("\n++ Multiplicative Approach ++\n"); for(i=1; i<=n; i++) { printf("[%6d] ==>", i); for(j=1; j<=m; j++) { result = i*j; /* directly multiply to produce results */ if (result < base) printf("%8d", result); else { /* convert the result from decimal to proper base format */ convResult = 0; k = 1; while(result > 0) { convResult = convResult + k * (result % base); result = result / base; k = 10 * k; } printf("%8d", convResult); } } printf("\n"); } /* creating multiplication table by repeated addition method */ printf("\n++ Additive Approach ++\n"); for(i=1; i<=n; i++) { printf("[%6d] ==>", i); result = 0; for(j=1; j<=m; j++) { result = result + i; /* repeated addition to produce results */ if (result < base) printf("%8d", result); else { convResult = 0; k = 1; tempResult = result; while(tempResult > 0) { /* convert the result from decimal to proper base format */ convResult = convResult + k * (tempResult % base); tempResult = tempResult / base; k = 10 * k; } printf("%8d", convResult); } } printf("\n"); } return 0; }