Skip to content

Commit ec9566a

Browse files
committed
Done but haven't completed tests and invalid input. Will do that later
1 parent ad6a027 commit ec9566a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

For loop/50. Decimal to octal.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ The Octal of 79 is 117.
2020
3 Get the remainder for the octal digit.
2121
4 Repeat the steps until the quotient is equal to 0.
2222
3. Invalid input
23-
4. Convert:
23+
+ 4. Convert:
2424
+ Function to count how many iterations of /8 there will be
2525
+ Power function
2626
+ Function to get the number int
2727
+ Reverse it
28-
5. Output
28+
+ 5. Output
2929
6. Test
30-
7. Cpplint test
31-
8. Add and push
30+
+ 7. Cpplint test
31+
+ 8. Add and push
3232
*/
3333

3434
#include <stdio.h>
@@ -38,17 +38,20 @@ int number_of_eights(int decimal_number);
3838
int power(int base, int exponent);
3939
int convert(int decimal_number, int division_by_eight);
4040
int reverse_number(int converted_number, int division_by_eight);
41+
void print_octal(int decimal_number, int result);
4142

4243
int main() {
4344
int decimal_number = input_decimal_number();
4445
int division_by_eight = number_of_eights(decimal_number);
4546
int converted = convert(decimal_number, division_by_eight);
46-
int converted_and_flipped = reverse_number(converted, division_by_eight);
47-
printf("Division by eight = %d\n", division_by_eight);
48-
printf("Converted but not flipped = %d, flipped = %d\n", converted, converted_and_flipped);
47+
print_octal(decimal_number, converted);
4948
return 0;
5049
}
5150

51+
void print_octal(int decimal_number, int result) {
52+
printf("The Octal of %d is %d.\n", decimal_number, result);
53+
}
54+
5255
// 711 -> 117
5356

5457
int reverse_number(int converted_number, int division_by_eight) {
@@ -76,7 +79,8 @@ I'll need that function once again when I will flip the number
7679
*/
7780

7881
int convert(int decimal_number, int division_by_eight) {
79-
int result = 0, quotient, remainder, temp_decimal = decimal_number, divider = 8, power_counter = division_by_eight;
82+
int result = 0, quotient, remainder, temp_decimal = decimal_number,
83+
divider = 8, power_counter = division_by_eight;
8084
for (int i = 0; i <= division_by_eight; ++i) {
8185
quotient = temp_decimal / divider;
8286
remainder = temp_decimal % divider;
@@ -88,6 +92,7 @@ int convert(int decimal_number, int division_by_eight) {
8892
--power_counter;
8993
temp_decimal = quotient;
9094
}
95+
result = reverse_number(result, division_by_eight);
9196
return result;
9297
}
9398

0 commit comments

Comments
 (0)