@@ -7,9 +7,24 @@ Expected Output :
7
7
The Octal of 79 is 117.
8
8
9
9
+ 1. Take input
10
- 2. Figure out how to convert to octal
10
+ + 2. Figure out how to convert to octal:
11
+ Devide the decimal by 8 and take the quotient to devide until it's zero
12
+ Put that remainder at the end of the octal number;
13
+ 79 % 8 == 7; quotient = 9
14
+ 9 % 8 == 1; q = 1
15
+ 1 % 8 == 1; q = 1
16
+ 117
17
+ Conversion steps:
18
+ 1 Divide the number by 8.
19
+ 2 Get the integer quotient for the next iteration.
20
+ 3 Get the remainder for the octal digit.
21
+ 4 Repeat the steps until the quotient is equal to 0.
11
22
3. Invalid input
12
- 4. Convert
23
+ 4. Convert:
24
+ + Function to count how many iterations of /8 there will be
25
+ + Power function
26
+ Function to get the number int
27
+ Reverse it
13
28
5. Output
14
29
6. Test
15
30
7. Cpplint test
@@ -19,11 +34,54 @@ The Octal of 79 is 117.
19
34
#include <stdio.h>
20
35
21
36
int input_decimal_number ();
37
+ int number_of_eights (int decimal_number );
38
+ int power (int base , int exponent );
39
+ int convert (int decimal_number );
22
40
23
41
int main () {
24
42
int decimal_number = input_decimal_number ();
43
+ int division_by_eight = number_of_eights (decimal_number );
44
+ // int converted = convert(decimal_number);
45
+ printf ("%d\n" , division_by_eight );
46
+ printf ("%d" , power (5 , 0 ));
25
47
return 0 ;
26
48
}
49
+ // Conversion steps:
50
+ // 1 Divide the number by 8.
51
+ // 2 Get the integer quotient for the next iteration.
52
+ // 3 Get the remainder for the octal digit.
53
+ // 4 Repeat the steps until the quotient is equal to 0.
54
+ // I will probably need a function to count how many iterations I will need to convert result into a number.
55
+ // I'll need that function once again when I will flip the number
56
+ int convert (int decimal_number ) {
57
+ return decimal_number ;
58
+ }
59
+
60
+ int power (int base , int exponent ) {
61
+ int result ;
62
+ if (exponent == 0 ) {
63
+ result = 1 ;
64
+ } else {
65
+ result = base ;
66
+ for (int i = 2 ; i <= exponent ; ++ i ) {
67
+ result *= base ;
68
+ }
69
+ }
70
+ return result ;
71
+ }
72
+
73
+ int number_of_eights (int decimal_number ) {
74
+ int divisor = 8 , quotient , counter = 0 , temp_decimal = decimal_number ;
75
+ for (int i = 0 ; i <= decimal_number ; ++ i ) {
76
+ quotient = temp_decimal / divisor ;
77
+ temp_decimal = quotient ;
78
+ ++ counter ;
79
+ if (quotient == 0 ) {
80
+ break ;
81
+ }
82
+ }
83
+ return counter ;
84
+ }
27
85
28
86
int input_decimal_number () {
29
87
int decimal_number ;
0 commit comments