Question: Using the program segment below, write two short functions to complete the program. Use the test cases to ensure the program works properly. Prototypes: void
Using the program segment below, write two short functions to complete the program. Use the test cases to ensure the program works properly.
Prototypes:
void int2bin(int, int[8]);
The first function will convert an integer that is between 0 - 255 to its binary representation. You are to store the binary number in the array passed to the function.
void printBinary(int[8]);
The second function will print the binary number stored in the array passed to the function.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Test 1: 13
Test 2: 16
Test 3: 255
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include
void int2bin(int, int[8]); void printBinary(int[8]); int readData(FILE*); int main(int argc, char* argv[]) { FILE* in = fopen(argv[1], "r"); int num = readData(in); int arr[8];
int2bin(num, arr); printBinary(arr);
}
void int2bin(int num, int arr[8]) { /*Write the function here*/
}
void printBinary(int arr[8]) { /*Write the function here*/ }
int readData(FILE* in) { int num = 0; fscanf(in, "%d", &num ); return num; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
