-
Notifications
You must be signed in to change notification settings - Fork 0
/
advancedClassificationRecursion.c
68 lines (59 loc) · 1.19 KB
/
advancedClassificationRecursion.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <math.h>
#include "NumClass.h"
int length(int n){
int tmp = n;
int count = 0;
while(tmp > 0){
count++;
tmp = tmp / 10;
}
return count;
}
int palindromeRecursive(int numbers[],int start , int end){
if(start >= end){
return 1;
}
if(numbers[start] != numbers[end]){
return 0;
}else{
return palindromeRecursive(numbers , start + 1 , end - 1);
}
}
int isPalindrome(int n){
int count = length(n);
int numbers[count];
for(int i = 0; i < count; i++){
numbers[i] = n % 10;
n /= 10;
}
int q = palindromeRecursive(numbers , 0 , count - 1);
if(q == 1){
return 1;
}
return 0;
}
int isArmstrongRec (int number , int power){
if(number == 0){
return 0;
}
else{
int temp = number%10;
return isArmstrongRec(number/10 ,power) + pow(temp, power);
}
}
int isArmstrong(int number){
int temp = number , counter=0;
while ((temp !=0))
{
counter++;
temp = temp/10;
}
temp = number;
if(number == isArmstrongRec(number,counter)){
return 1;
}
else{
return 0;
}
}