@@ -20,15 +20,15 @@ The Octal of 79 is 117.
20
20
3 Get the remainder for the octal digit.
21
21
4 Repeat the steps until the quotient is equal to 0.
22
22
3. Invalid input
23
- 4. Convert:
23
+ + 4. Convert:
24
24
+ Function to count how many iterations of /8 there will be
25
25
+ Power function
26
26
+ Function to get the number int
27
27
+ Reverse it
28
- 5. Output
28
+ + 5. Output
29
29
6. Test
30
- 7. Cpplint test
31
- 8. Add and push
30
+ + 7. Cpplint test
31
+ + 8. Add and push
32
32
*/
33
33
34
34
#include <stdio.h>
@@ -38,17 +38,20 @@ int number_of_eights(int decimal_number);
38
38
int power (int base , int exponent );
39
39
int convert (int decimal_number , int division_by_eight );
40
40
int reverse_number (int converted_number , int division_by_eight );
41
+ void print_octal (int decimal_number , int result );
41
42
42
43
int main () {
43
44
int decimal_number = input_decimal_number ();
44
45
int division_by_eight = number_of_eights (decimal_number );
45
46
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 );
49
48
return 0 ;
50
49
}
51
50
51
+ void print_octal (int decimal_number , int result ) {
52
+ printf ("The Octal of %d is %d.\n" , decimal_number , result );
53
+ }
54
+
52
55
// 711 -> 117
53
56
54
57
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
76
79
*/
77
80
78
81
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 ;
80
84
for (int i = 0 ; i <= division_by_eight ; ++ i ) {
81
85
quotient = temp_decimal / divider ;
82
86
remainder = temp_decimal % divider ;
@@ -88,6 +92,7 @@ int convert(int decimal_number, int division_by_eight) {
88
92
-- power_counter ;
89
93
temp_decimal = quotient ;
90
94
}
95
+ result = reverse_number (result , division_by_eight );
91
96
return result ;
92
97
}
93
98
0 commit comments