Created
July 29, 2017 04:24
-
-
Save PVaid/b6415c8036f575177276083fb7d02628 to your computer and use it in GitHub Desktop.
Continuous Niven Numbers in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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