Program to check the given number is Perfect number or not

 Program to check the given number is Perfect number or not


I/P:

6


O/P:

Perfect


Explanation :


6 divisors are 2 , 3 ,1  its sum is equal to the given num so its a perfect num


PROGRAM:

import java.util.*;
public class perfect {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        int iNum=sc.nextInt();
        int sum=0;
        int a=iNum;
        for(int i=1;i<iNum;i++)
        {
            if(iNum%i==0)
            {
                sum+=i;
            }
        }
        if(sum==a)
        {
            System.out.println("Perfect");
        }
        else {
            System.out.println("Not Perfect");
        }

    }

}


// 6

//2 3 1=>2 + 3 +1=6==6
// Perfect


Comments

Popular posts from this blog

PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION

PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY

TELEPHONE BOOK USING HASHMAP