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 .
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 : :
OUTPUT : :
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