Question
C++ code to find perfect number using recursion according to given google test cases Kindly solve this error.OR Write a program according to given google
C++ code to find perfect number using recursion according to given google test cases
Kindly solve this error.OR Write a program according to given google test cases
PROGRAM(HEADER):
#pragma once #include
bool isperfectNumber(int num, int x = 0) { //int x=0; if (x == 1) return 1;
else if (num % x == 0)/*if x is a proper divisor*/ { return x + isperfectNumber(num, x - 1); } else { return isperfectNumber(num, x - 1); } if (isperfectNumber(num, num / 2) == num) return false; else return true;
}
GOOGLE TEST CASES:
TEST(PerfectNumber, Test1) { ASSERT_EQ(true, isperfectNumber(28)); }
TEST(PerfectNumber, Test2) { ASSERT_EQ(false, isperfectNumber(17)); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started