Q:

C++ Program to find Perfect Number using loop

belongs to collection: C++ Number Solved Programs

0

Write a C++ Program to find Perfect Number using loop. Here’s simple C++ Program to find Perfect Number using loop in C++ Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Normally, when we work with Numbers, we use primitive data types such as int, short, long, float and double, etc. The number data types, their possible values and number ranges have been explained while discussing C++ Data Types.

 
 

Perfect number : :


A perfect numbers is a positive number that equals the sum of its divisors, excluding itself. This is also known as its aliquot sum. At this time, it is unknown how many perfect numbers truly exist in our number system.

While we have discovered 48 perfect numbers, the fact that there are an infinite number of prime numbers leads us to believe that there could be an infinite number of perfect numbers.


Here is source code of the C++ Program to find Perfect Number using loop. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.

 

SOURCE CODE : :

/* C++ Program to find Perfect Number using loop */

#include<iostream>
using namespace std;

int main()                 //Start of main
{
   int i=1, u=1, sum=0;
   while(i<=500)
 {                                  // start of first loop.

   while(u<=500)
   {                               //start of second loop.
     if(u<i)
     {
      if(i%u==0 )
      sum=sum+u;
     }                          //End of if statement

     u++;
   }                           //End of second loop

   if(sum==i)
   {
    cout<<i<<" is a perfect number."<<"\n";
   }

   i++;
   u=1;  sum=0;
 }                             //End of First loop
   return 0;
 }                            //End of main

OUTPUT : :


**************** OUTPUT *****************


6 is a perfect number.

28 is a perfect number.

496 is a perfect number.

Above is the source code for C++ Program to find Perfect Number using loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Number Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Program to Find Grade of a Student using if el... >>
<< C++ Program to find Area and Perimeter of Rectangl...