Perfect numbers in the range Write a program to find the perfect numbers between a given range. Input Format: The first input contains an integer which denotes the starting number of the range The second input contains an integer which denotes the ending number of the range
Answers
Answered by
0
Answer:
Perfect numbers in the range
Write a program to find the perfect numbers between a given range.
Input Format:
The first input contains an integer which denotes the starting number of the range
The second input contains an integer which denotes the ending number of the range
Output Format:
Print the perfect numbers in a given range
Sample Input:
1
10
Sample Output:
6
Answered by
0
Answer:
#include<iostream>
main()
{
int n1,n2,p=0;
std::cin>>n1>>n2;
for(int i=n1;i<=n2;i++)
{
for(int j=1;j<i;j++)
{
if(i%j==0)
p+=j;
else
p+=0;
}
if(p==i)
{
std::cout<<p<<" ";
p*=0;
}
else
p*=0;
}
}
Explanation:
Similar questions
Social Sciences,
4 months ago
Business Studies,
4 months ago
English,
9 months ago
English,
9 months ago
Social Sciences,
1 year ago