Skip to content

Commit 84108ee

Browse files
committed
Solved Armstrong in range
1 parent 6dad75d commit 84108ee

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

For loop/00 - Extra exercises - B. Armstrong in range.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ The Armstrong numbers are :
1111
Rework regular Armstrong number solution to work in a range:
1212
+ 1. Correct the input
1313
+ 2. Find numbers inside a range
14-
3. Test
15-
4. Cppling
16-
5. Add and push
14+
+ 3. Test:
15+
Input: 1 and 912985153. Output:
16+
1 2 3 4 5 6 7 8 9 153 370 371 407 1634
17+
8208 9474 54748 92727 93084 548834 1741725
18+
4210818 9800817 9926315 24678050 24678051 472335975 534494836 912985153
19+
88593477 146511208
20+
+ 4. Cppling
21+
+ 5. Add and push
1722
*/
1823

1924
#include <stdio.h>
@@ -25,11 +30,8 @@ int power(int base, int exponent);
2530
int find_number_of_digits(int number);
2631
int is_armstrong(int number, int number_of_digits);
2732
void print_armstrong_in_range(int start, int end);
28-
void test(int number, int expected, int test_number);
29-
3033

3134
int main() {
32-
// Regular run of the program
3335
int start = input_start();
3436
if (start >= 0) {
3537
int end = input_end();
@@ -42,21 +44,8 @@ int main() {
4244
return 0;
4345
}
4446

45-
// 0 - false, 1 - true
46-
void test(int number, int expected, int test_number) {
47-
int number_of_digits = find_number_of_digits(number);
48-
int actual = is_armstrong(number, number_of_digits);
49-
if (actual == expected) {
50-
printf("Test #%d: number = %d, expected = %d, actual = %d\nSuccess\n",
51-
test_number, number, expected, actual);
52-
} else {
53-
printf("Test #%d: number = %d, expected = %d, actual = %d\nFailed\n",
54-
test_number, number, expected, actual);
55-
}
56-
}
57-
5847
void print_armstrong_in_range(int start, int end) {
59-
printf("The Armstrong numbers are:\n");
48+
printf("The Armstrong numbers are:\n");
6049
for (int i = start; i <= end; i++) {
6150
if (is_armstrong(i, find_number_of_digits(i))) {
6251
printf("%d ", i);

0 commit comments

Comments
 (0)