-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvancedClassificationLoop.c
More file actions
52 lines (44 loc) · 1.11 KB
/
advancedClassificationLoop.c
File metadata and controls
52 lines (44 loc) · 1.11 KB
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
#include <stdio.h>
#include "NumClass.h"
// Function to calculate the power of a number
int powerloop(int base, int exponent) {
int result = 1;
for (int i = 0; i < exponent; ++i) {
result *= base;
}
return result;
}
// Function to count the number of digits in a number
int countDigits(int num) {
int count = 0;
while (num != 0) {
num /= 10;
++count;
}
return count;
}
// Function to check if a number is an Armstrong number
int isArmstrong(int num) {
int originalNum = num;
int n = countDigits(num);
int sum = 0;
while (num > 0) {
int digit = num % 10;
sum += powerloop(digit, n);
num /= 10;
}
return (sum == originalNum);
}
// Function to check if an integer is a palindrome
int isPalindrome(int num) {
int originalNum = num;
int reversedNum = 0;
// Reverse the integer
while (num > 0) {
int digit = num % 10;
reversedNum = reversedNum * 10 + digit;
num /= 10;
}
// Check if the reversed integer is equal to the original
return (originalNum == reversedNum) ? 1 : 0;
}