File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ The equivalent Decimal Number : 485
11
11
745 = (7 * 8^2) + (4 * 8^1) + (5 * 8^0) = 485
12
12
+ 1.5 Input
13
13
+ 2. Pow function
14
- 3. Function to count amount of digits
14
+ + 3. Function to count amount of digits
15
15
4. Write function to iterate over digits and return sum of powers
16
16
+ 5. Invalid input
17
17
6. Test
@@ -29,17 +29,26 @@ enum boolean_for_validation {
29
29
int input_octal (int * octal );
30
30
void print_invalid_input ();
31
31
int power (int base , int exponent );
32
+ int find_number_of_digits (int octal );
32
33
33
34
int main () {
34
35
int octal = 0 ;
35
36
if (input_octal (& octal )) {
36
- printf ("%d" , power (octal , 0 ));
37
+ printf ("%d\n " , find_number_of_digits (octal ));
37
38
} else {
38
39
print_invalid_input ();
39
40
}
40
41
return 0 ;
41
42
}
42
43
44
+ int find_number_of_digits (int octal ) {
45
+ int counter = 0 ;
46
+ for (int i = octal ; i > 0 ; i /= 10 ) {
47
+ ++ counter ;
48
+ }
49
+ return counter ;
50
+ }
51
+
43
52
int power (int base , int exponent ) {
44
53
int result = base ;
45
54
if (exponent == 0 ) {
You can’t perform that action at this time.
0 commit comments