This C++ program prints all the perfect cubes below 1000. The program first calculates the value below which all the numbers have their cubes less than 1000 and then prints all their cubes.
Here is the source code of the C++ program which prints all the perfect cubes below 1000. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Print All Perfect Cubes Below 1000
*/
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int max = 1000, lim;
lim = cbrt(max);
cout << "Perfect cubes below 1000" << endl;
for(int i = 1; i < lim; i++)
{
cout << i << " ^ 3 : " << setw(3) << setfill('0')
<< pow(i, 3) << endl;
}
}
$ a.out Perfect cubes below 1000 1 ^ 3 : 001 2 ^ 3 : 008 3 ^ 3 : 027 4 ^ 3 : 064 5 ^ 3 : 125 6 ^ 3 : 216 7 ^ 3 : 343 8 ^ 3 : 512 9 ^ 3 : 729
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Apply for C++ Internship
- Apply for Computer Science Internship
- Check Programming Books
- Practice Computer Science MCQs
- Check Computer Science Books