Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++: Kaprekar number test loop (list all Kaprekar numbers under 10,000) For some reason, I'm missing numbers between 9 and 2223..... #include using namespace std;

c++: Kaprekar number test loop (list all Kaprekar numbers under 10,000)

For some reason, I'm missing numbers between 9 and 2223.....

#include

using namespace std;

int main(){

//declare variables

int num, squaredNum, firstHalf, secondHalf, unit, test;

//initialize number

num = 1;

//while loop

while(num < 10000){

squaredNum = num * num;

if (squaredNum < 100){

unit = 10;

}

else if (squaredNum < 1000){

unit = 100;

}

else if (squaredNum < 10000){

unit = 1000;

}

else if (squaredNum < 100000){

unit = 10000;

}

firstHalf = squaredNum/unit;

secondHalf = squaredNum%unit;

test = firstHalf + secondHalf;

if (test == num){

cout << num << " is a kaprekar number!" << endl;

num++; //increment number

}else {

num++; //increment & continue to next number

}

}//end while loop

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

5. What information would the team members need?

Answered: 1 week ago