Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CODE in C/Mathematical/Niven.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;

// A Niven number is one in which the sum of the digits is divisible by n
bool checkNiven(int n)
{
// calculate sum of digits
int sum = 0;
for (int temp = n; temp > 0; temp /= 10)
sum += temp % 10;

// Return true if it is a Niven number
return (n % sum == 0);
}

int main()
{
int n;
cout<<"Program to check if it is a Niven number \nEnter a number : ";
cin>>n;
bool result = checkNiven(n);
if(result)
cout<<"Yes\n";
else
cout<<"No\n";
return 0;
}