Skip to content

Commit 618d64b

Browse files
committed
Niven Number Algo
1 parent 11bc331 commit 618d64b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

niven.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int num, sum = 0;
6+
cout << "Enter a number: ";
7+
cin >> num;
8+
int n = num;
9+
while (num > 0)
10+
{
11+
int rem = num % 10;
12+
sum = sum + rem;
13+
num = num / 10;
14+
}
15+
if (n % sum == 0)
16+
cout << n << " Yes! A Niven number";
17+
else
18+
cout << n << " Not A Niven number";
19+
return 0;
20+
}

niven.exe

3.12 MB
Binary file not shown.

0 commit comments

Comments
 (0)