# Perfect number program

#### Check perfect number in c

``` #include<stdio.h> #include<conio.h> void CheckPerfectNumberRange(int start,int end); void CheckPerfectNumber(int number); void main() { int num,max,min; char input; printf("Enter 'A' for Check Perfect Number or \nEnter 'B' for Check Perfect Number in a range \n"); scanf("%c",&input); printf("\n"); if(input=='A' || input=='a') { printf("You choose A option to check the perfect number \n"); printf("\n"); printf("Enter your number to check perfect number or not \n"); scanf("%d",&num); printf("\n"); CheckPerfectNumber(num); } else if(input=='B' || input=='b') { printf("You choose B option to check the perfect number in a range \n"); printf("\n"); printf("Enter your starting number \n"); scanf("%d",&min); printf("Enter your ending number \n"); scanf("%d",&max); printf("\n"); CheckPerfectNumberRange(min,max); } else { printf("Your choose a wrong option \n"); } getch(); } void CheckPerfectNumber(int number) { int reminder,sum=0; for(int i=1;i<number;i++) { reminder = number%i; if(reminder==0) { sum = sum + i; } } if(number==sum) { printf("Result = Yes, %d is a perfect number",number); } else { printf("Result = No, %d is not a perfect number",number); } } void CheckPerfectNumberRange(int start,int end) { int r; printf("Perfect Number between %d and %d \n",start,end); for(int i=start;i<=end;i++) { int sum=0; for(int j=1;j<i;j++) { r=i%j; if(r==0) { sum+=j; } } if(sum==i) { printf("%d ",sum); } } } ```

#### Output

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range A You choose A option to check the perfect number Enter your number to check perfect number or not 6 Result = Yes, 6 is a perfect number ```

#### Output(Range)

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range B You choose B option to check the perfect number in a range Enter your starting number 1 Enter your ending number 1000 Perfect Number between 1 and 1000 6 28 496 ```

#### Check perfect number in c++

``` #include<iostream> #include<conio.h> using namespace std; class PerfectNumber { public: void CheckPerfectNumber(int number) { int reminder,sum=0; for(int i=1;i<number;i++) { reminder = number%i; if(reminder==0) { sum = sum + i; } } if(number==sum) { cout<<"Result = Yes, "<<number<<" is a perfect number"; } else { cout<<"Result = No,"<<number<<" is not a perfect number"; } } public: void CheckPerfectNumberRange(int start,int end) { int r; cout<<"Perfect Number between "<<start<<" and "<<end<<"\n"; for(int i=start;i<=end;i++) { int sum=0; for(int j=1;j<i;j++) { r=i%j; if(r==0) { sum+=j; } } if(sum==i) { cout<<sum<< " "; } } } }; void main() { PerfectNumber perfectNumber; int num,max,min; char input; cout<<"Enter 'A' for Check Perfect Number or \nEnter 'B' for Check Perfect Number in a range \n"; cin>>input; cout<<"\n"; if(input=='A' || input=='a') { cout<<"You choose A option to check the perfect number \n"; cout<<"\n"; cout<<"Enter your number to check perfect number or not \n"; cin>>num; cout<<"\n"; perfectNumber.CheckPerfectNumber(num); } else if(input=='B' || input=='b') { cout<<"You choose B option to check the perfect number in a range \n"; cout<<"\n"; cout<<"Enter your starting number \n"; cin>>min; cout<<"Enter your ending number \n"; cin>>max; cout<<"\n"; perfectNumber.CheckPerfectNumberRange(min,max); } else { cout<<"Your choose a wrong option \n"; } getch(); } ```

#### Output

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range A You choose A option to check the perfect number Enter your number to check perfect number or not 28 Result = Yes, 28 is a perfect number ```

#### Output(Range)

```<code>Enter 'A' for Check Perfect Number or
Enter 'B' for Check Perfect Number in a range
B

You choose B option to check the perfect number in a range

1
2000

Perfect Number between 1 and 2000
6 28 496
```

#### Check perfect number in c#

``` using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PerfectNumber { class PerfectNumber { public void CheckPerfectNumber(int number) { int reminder,sum=0; for(int i=1;i<number;i++) { reminder = number%i; if(reminder==0) { sum = sum + i; } } if(number==sum) { Console.Write("Result = Yes, "+number+" is a perfect number"); } else { Console.Write("Result = No,"+number+" is not a perfect number"); } } void CheckPerfectNumberRange(int start,int end) { int r; Console.Write("Perfect Number between "+start+" and "+end+"\n"); for(int i=start;i<=end;i++) { int sum=0; for(int j=1;j<i;j++) { r=i%j; if(r==0) { sum+=j; } } if(sum==i) { Console.Write(sum+ " "); } } } static void Main(string[] args) { PerfectNumber perfectNumber = new PerfectNumber() ; int num, max, min; char input; Console.Write("Enter 'A' for Check Perfect Number or \nEnter 'B' for Check Perfect Number in a range \n"); input=Convert.ToChar(Console.ReadLine()); Console.WriteLine(); if (input == 'A' || input == 'a') { Console.Write("You choose A option to check the perfect number \n"); Console.WriteLine(); Console.Write("Enter your number to check perfect number or not \n"); num=Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); perfectNumber.CheckPerfectNumber(num); } else if (input == 'B' || input == 'b') { Console.Write("You choose B option to check the perfect number in a range \n"); Console.WriteLine(); Console.Write("Enter your starting number \n"); min=Convert.ToInt32(Console.ReadLine()); Console.Write("Enter your ending number \n"); max=Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); perfectNumber.CheckPerfectNumberRange(min, max); } else { Console.Write("Your choose a wrong option \n"); } Console.ReadLine(); } } } ```

#### Output

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range A You choose A option to check the perfect number Enter your number to check perfect number or not 496 Result = Yes, 496 is a perfect number ```

#### Output(Range)

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range b You choose B option to check the perfect number in a range Enter your starting number 1 Enter your ending number 10000 Perfect Number between 1 and 10000 6 28 496 8128 ```

#### Check perfect number in java

``` import java.util.*; class PerfectNumber { public void CheckPerfectNumber(int number) { int reminder,sum=0; for(int i=1;i<number;i++) { reminder = number%i; if(reminder==0) { sum = sum + i; } } if(number==sum) { System.out.print("Result = Yes, "+number+" is a perfect number"); } else { System.out.print("Result = No,"+number+" is not a perfect number"); } } public void CheckPerfectNumberRange(int start,int end) { int r; System.out.print("Perfect Number between "+start+" and "+end+"\n"); for(int i=start;i<=end;i++) { int sum=0; for(int j=1;j<i;j++) { r=i%j; if(r==0) { sum+=j; } } if(sum==i) { System.out.print(sum+ " "); } } } } class examples { public static void main(String[] args) { Scanner obj= new Scanner(System.in); PerfectNumber perfectNumber=new PerfectNumber(); int num, max, min; String input; System.out.print("Enter 'A' for Check Perfect Number or \nEnter 'B' for Check Perfect Number in a range \n"); input=obj.next(); System.out.println(); if (input.charAt(0) == 'A' || input.charAt(0) == 'a') { System.out.print("You choose A option to check the perfect number \n"); System.out.println(); System.out.print("Enter your number to check perfect number or not \n"); num=obj.nextInt(); System.out.println(); perfectNumber.CheckPerfectNumber(num); } else if (input.charAt(0) == 'B' || input.charAt(0) == 'b') { System.out.print("You choose B option to check the perfect number in a range \n"); System.out.println(); System.out.print("Enter your starting number \n"); min=obj.nextInt(); System.out.print("Enter your ending number \n"); max=obj.nextInt(); System.out.println(); perfectNumber.CheckPerfectNumberRange(min, max); } else { System.out.print("Your choose a wrong option \n"); } } } ```

#### Output

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range A You choose A option to check the perfect number Enter your number to check perfect number or not 8128 Result = Yes, 8128 is a perfect number ```

#### Output(Range)

```Enter 'A' for Check Perfect Number or Enter 'B' for Check Perfect Number in a range B You choose B option to check the perfect number in a range Enter your starting number 1 Enter your ending number 100000 Perfect Number between 1 and 100000 6 28 496 8128 ```

### Write a comment

Name Email Message