Trimorphic

Hello, everyone!
Awesome forum!

Ok, here we are. You have probably heard it a lot of times but I have just started getting familiar with C++ programming. So I've been asked to create a program that finds, counts and shows the trimorphic numbers between 9 and 100. The program should show in the end the amount of the trimorphic numbers.
Trimorphic numbers are called numbers whose cube ends in the number itself, e.g. 4^3 = 64, 24^3 = 13824 etc.

This is what I have done so far:

#include <iostream>
using namespace std;

int main()
{
cout << "TRIMORPHIC NUMBERS" << endl;
int i;
int cube;
for (i=9; i<=100; i++)
{
cube=i*i*i;
if (i>=10)
{
if (cube % 100 == i)
cout << "Cube of " << i << "= " << cube << endl;
}
if (i<10)
{
if (cube % 10 == i)
cout << "Cube of " << i << "= " << cube << endl;
}
}
return 0;
}

But I still cannot find the way to display the amount of number (in my case 8).

Any help appreciated and I'll be eternally grateful!

Cheers from "Dreamer/Programmer" !!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int main()
{
	cout << "TRIMORPHIC NUMBERS" << endl;
	int nb_cube = 0;
	for (int i=9; i<=100; i++)
	{
		int cube=i*i*i;
		if (cube % 10 == i % 10)
		{
			cout << "Cube of " << i << "= " << cube << endl;
			nb_cube++;
		}
	}
	cout << "You found " << nb_cube << " trimorphic numbers" << endl;
	return 0;
}
Last edited on
Thank you Stewbond!

That was really helpful!
Topic archived. No new replies allowed.