-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber.cs
More file actions
42 lines (38 loc) · 727 Bytes
/
Number.cs
File metadata and controls
42 lines (38 loc) · 727 Bytes
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
using System;
namespace ConsoleApp66
{
class Program
{
static void Main(string[] args)
{
int n = 151; // 151 opposite 151
int k = 153; // 1^3 = 1 + 5^3 = 125 + 3^3 = 27 = 153
var t = Palindrome(n);
Console.WriteLine(t);
var p = Armstrong(k);
Console.WriteLine(p);
}
private static int Armstrong(int k)
{
int sum = 0;
while (k > 0)
{
int r = k % 10;
sum = sum + (r * r * r);
k = k / 10;
}
return sum;
}
private static int Palindrome(int n)
{
int sum = 0;
while(n > 0)
{
int r = n % 10;
sum = (sum * 10) + r;
n /= 10;
}
return sum;
}
}
}