PERFECT NUMBERS
Code :
#include<stdio.h>
int main()
{
int s, n, sum = 0,no_per = 0, perf = 0;
printf("==================================\n");
printf("\t PERFECT NUMBER\n");
printf("==================================\n");
printf("Enter lower limit number : ");
scanf("%d", &s);
printf("Enter upper limit number : ");
scanf("%d", &n);
printf("\n");
printf("All Perfect Numbers Between %d and %d are,\n\n", s, n);
for(int j=s; j<=n; j++)
{
sum = 0;
for(int i=1; i<j; i++)
{
if(j%i == 0)
{
sum += i;
}
}
if(sum == j)
{
printf("%d ", j);
}
else
{
no_per++;
}
}
if(no_per == ((n-s)+1))
{
printf("No Perfect Numbers in given range !!");
}
printf("\n----------------------------------\n");
return 0;
}
Come again Learn again !
« iCodeBuzz »
No comments:
Post a Comment