Write a program in C that asks the user for input for two in
Write a program in C++ that asks the user for input for two integer values: startval, and endval.
The program will then find all Perfect Numbers that fall between startval and endval. A perfect number is a number equal to the sum of all its proper divisors (divisors smaller than the number) including 1. The number 6 is the smallest perfect number; because it is the sum of its divisors 1, 2, and 3 (1+2+3 = 6). The next perfect number is 28 (28 = 1+2+4+7+14).
The search for the Perfect Number will require two loops (nested). The outer loop will step thru the range of numbers between startval and endval. The inner loop will step thru the values from 1 to (outerval/2) to determine the factors of the number.
Write and use a function called isAFactor that accepts two int args, and determines if the second number is a factor of the first. It should return a bool value. When a number is found, print out a message: Xxx is a Perfect Number. If no Perfect Numbers can be found in the given range, print the message: No Perfect Numbers found between xxxx and yyyy.
Sample output:
OCUsers Administrator documents\\visual Studio 2010Projects Sample\\Debug\\Sampleexe a Enter starting integer: 1 Enter ending integer: 190 6 is a perfect number. 28 is a perfect number. Press any key to continue . . . CCAUsers\\Administrator documents visual studio 2010\\Projects SampleDebug Sample exe - Enter starting integer: 100 Enter ending integer: 200 There is no perfect number between 100 and 200. Press any key to continue . . .Solution
#include<iostream.h>
#include<conio.h>
bool isAfactor(int a,int b)
{
if(( ab)==0)
return true;
else
return false;
}
int main()
{
int start Val,endval,i,n,sum=0,k=0;
clrscr();
cout<<\"Enter starting integer : \";
cin>>startval;
cout<<\"Enter ending value: \";
cin>>endval;
for(n=startval;n<=endval;n++)
{
sum=0;
for(i=1;i<n;i++)
{
if(isAfactor(n,i))
sum=sum+i;
}
if(sum==n)
{
k++;
cout<<n<< \" is a perfect number\"<<endl;
}
}
if(k==0)
cout<<\"There is no perfect number between \"<<startval<<\" \"<<endval<<endl;
cout<<\"Press any key to continue\";
return 0;
}

