Facebook Google Plus YouTube

UVA Problem 640 ( Self Numbers) Solution

UVA Problem 640 ( Self Numbers): Is a basic UVa problem.

Details link:

 

Problem Details:

This is a Straightforward problem.

 

problem solution:

#include <stdio.h>

#include <math.h>



int d[1000010];



int generator(int num)

{

    int sum = num;

    while(num > 0)

    {

        sum += num%10;

        num /= 10;

    }

    return sum;

}



int main()

{

    int i;

//for(i=1;i<=100;i++)

    for(i=1;i<=1000000;i++)

    {

        if(d[i] == 0)

            printf("%d\n",i);

        d[generator(i)] = 1;

    }



    return 0;

}

 

Leave a Reply

%d bloggers like this: