Friday, November 11, 2011

How to generate perfect number with in a range


How to generate perfect number with in a range
#include<stdio.h>
void main(){
  int n,i,sum;
  int min,max;

  printf("Enter the left range: ");
  scanf("%d",&min);

  printf("Enter the right range: ");
  scanf("%d",&max);

  printf("Perfect numbers in given range is: ");
  for(n=min;n<=max;n++){
    i=1;
    sum = 0;

    while(i<n){
      if(n%i==0)
           sum=sum+i;
          i++;
    }

    if(sum==n)
      printf("%d ",n);
  }
}

0 comments:

Post a Comment

You are most welcome for making comments here. I will consider your view and will reply you soon.