Search code examples
cperfect-numbers

Perfect Number In C


I need to write a C program to find the Perfect Number..

main()
{
    int n=1000,sum = 0;
    for(int num = 1; num <= n; num++)
    {
        sum = 0;
        for(int i = 1; i < num; i++)
        {
            if(!(num%i))
            {
                sum+=i;
            }
        }
        if(sum == num)
            printf("\n%d",num);
    }
}

if(!(num%i)) - This is d line I do not understand.

If there is any other simple method do please suggest me


Solution

  • if(!(num%i)) simply means if( (num%i) == 0 )