Skip to content

Instantly share code, notes, and snippets.

@PVaid
Created July 29, 2017 04:24
Show Gist options
  • Save PVaid/b6415c8036f575177276083fb7d02628 to your computer and use it in GitHub Desktop.
Save PVaid/b6415c8036f575177276083fb7d02628 to your computer and use it in GitHub Desktop.
Continuous Niven Numbers in C
#include <stdio.h>
#include<conio.h>
static int sum(int n)
{
int sum = 0;
do
{
sum += n % 10;
} while (n /= 10);
return sum;
}
int main(void)
{
int n, i, j;
for (n = 1, i = j = 0; !i; ++n)
{
if (n % sum(n) == 0)
{
if (j++ < 20) printf("%d ", n);
if (n > 1000) i = printf("\n%d\n", n);
}
}
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment