Display perfect numbers between 1 to 50 - C

Write a C program to display all perfect numbers between 1 to 50 by using function.

Solution:

#include<stdio.h>
void perfect()
{
     int n,i,sum;
     for(n=1;n<=50;n++)
     {
          i=1;
          sum = 0;
          while(i<n)
          {
               if(n%i==0)
                    sum=sum+i;
               i++;
          }
          if(sum==n)
               printf("\t%d",n);
     }
}
int main()
{
     printf("Perfect Numbers Between 1 to 50\n\n");
     perfect();
     return 0;
}


Output:

perfect numbers 1 to 50