Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help on one of my C programming assignment. I am to finish the function 'printMultTable' to display a multiplication table of hexadecimal.

I need some help on one of my C programming assignment. I am to finish the function 'printMultTable' to display a multiplication table of hexadecimal. I'm stuck and I don't know what to do. Here's what the professor gave us to start with.

#include

#include

char convertToChar(int i, int base);

void printNumber(int i, int base, int field_width, int char_count);

void printMultTable(int base);

void printAddTable(int base);

int main()

{

int i = 59;

int base, fieldWidth;

/*

do{

printf("enter an integer, a base, and the field width ");

scanf("%d%d%d",&i, &base, &fieldWidth);

printf("...");

printNumber(i, base, fieldWidth, 0);

printf("...");

putchar(' ');

}while(0);

*/

printf("This program will print a multiplication base for any base 2 to 36 ");

printf("What base would you like to use? ");

scanf("%d", &base);

if (base >= 2 && base <= 36){

printf("Mult table ");

printMultTable(base);

printf(" Add table ");

printAddTable(base);

}else{

printf("invalid base ");

}

system("pause");

return 0;

}

/*

i < base

*/

char convertToChar(int i, int base)

{

char answer;

//real programs do error checking

if ( i < 10){

answer = i + '0';

}else{

answer = i + 'A' - 10;

}

return answer;

}

void printNumber(int i, int base, int field_width, int char_count)

{

char ch;

char_count++;

if (i < base){

int k;

ch = convertToChar(i, base);

//see if we need to pad it with spaces

for(k = char_count; k < field_width; ++k)

{

putchar(' ');

}

}else{

int r = i % base;

ch = convertToChar(r, base);

i = i /base;

printNumber(i, base, field_width, char_count);

}

printf("%c", ch);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

=+ Is the information presented in an objective manner?

Answered: 1 week ago

Question

List the types of turnover.

Answered: 1 week ago