### 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" !!!
 ``12345678910111213141516171819`` ``````#include 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!