1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // Ok to copy/adapt code from *THIS FILE* (only)
// IMPLEMENTATION CODE
#include <stdio.h>
#include <stdlib.h>
// Angle brackets are for standard include files.
#include "hw02.h"
// Double quotes are for your files.
void print_integer(int n, int radix, char* prefix) {
if (n <= 9) {
fputc('0' + n, stdout);
// fputc(48 + n, stdout); // WRONG!!!
// Do not type an int where you mean a char
}
else {
fputc('a' + n - 10, stdout);
}
}
// You do not need a switch/case. That may work but
// it is bonkers inefficient.
// Do not use an array.
// Beware of integer overflow.
// Test easy cases, edge cases, and corner cases.
|
© Copyright 2020 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.