Examples of C part 27 print all perfect number till n

Program :
#include<stdio.h>
#include<math.h>
main()
{
  int num,i,sum,j;
  printf("Enter a number to know all perfect numbers till n\n");
  scanf("%d",&num);
  printf("The perfect numbers between 1 and %d are:",num);
  for(i=1;i<=num;i++)
  {
    sum=0;
    for(j=1;j<i;j++)
    {
      if(i%j==0)
      {
        sum+=j;
      }
    }
    if(sum==i)
    {
      printf("%d\n",i);
    }
  }
}
Output:
Enter a number to know all perfect numbers till n
1000
The perfect numbers between 1 and 1000 are:6
28
496
Explanation:
This Program is same as the "Check Whether number is Perfect or Not" where we found whether the given number is Perfect or not. The only change here is we use forloop from 1 to the given number(say 1000 in our case) and check each number whether it is perfect or not. So it checks from 1,2,3,...1000 and if any number is having the sum of it's divisors equal to the number then it is printed else not.