Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The prototype of other functions are here: void printBitArray(unsigned char theB

ID: 3889578 • Letter: T

Question

The prototype of other functions are here:

void printBitArray(unsigned char theBits[SIZE_INT]);

void toBits(unsigned short value,unsigned char inBits[SIZE_INT]);

unsigned short factorial(unsigned short num);

Write a main function that, inputs an integer number (of size unsigned short), calculates the factorial of that number, uses toBits to place the 16 bits of the result into 16 separate locations of a byte sized integer array, and then uses printBits to output the contents of that array. Finally, the program should give the user the option of re-running with different input.

Explanation / Answer

Hi,

I have provided the code below. Since you haven't provided the implementation of the functions, I couldn't test them so If you face any difficulties, feel free to comment below.

// code starts here

#include <stdio.h>
#define SIZE_INT 16

void printBitArray(unsigned char theBits[SIZE_INT]);
void toBits(unsigned short value,unsigned char inBits[SIZE_INT]);
unsigned short factorial(unsigned short num);

int main()
{
printf("Hello, World! ");
  
char userInput = '0';
unsigned short userInputNumber;
  
do{
scanf("Input an integer number %hu", &userInputNumber);
unsigned short factorialOfNumber = factorial(userInputNumber);
unsigned char bits[16];
toBits(factorialOfNumber, bits);
printBitArray(bits);
printf("Press 'a' to enter a number again or any other character to cancel ");
userInput = scanf(" %c", &userInput);
}while(userInput == 'a');

return 0;
}

//code ends here

Hope it helps!