Program to print square and cube of given number
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int small_number = 0, larger_number = 0, increment =
0, temp = 0;
cout
<< "\n\n\t\tSquare and Cube from Smaller
number to Larger number";
cout
<< "\n\n
Smaller Number - ";
cin
>> small_number;
cout
<< "\n\n
Larger Number - ";
cin
>> larger_number;
if(small_number <= larger_number)
{
cout
<< "\n\n
Increment Value - ";
cin
>> increment;
cout
<< "\n\n\t__ Value __ \t\t __ Square
__\t\t __ Cube __";
for(temp = small_number; temp <= larger_number;
temp = temp + increment)
{
cout
<< "\n\n\t " << temp << "\t\t\t
" << temp * temp << "\t\t\t " << temp * temp *
temp;
}
}
else
{
cout
<< "\n\n\tSmaller number entered is
greater than Larger number";
}
getch();
return 0;
}
Program will scan three numbers -
- Smaller number (the initialization point of the for loop)
- Larger number (the number till which the for loop is going to run)
- Increment number (the number with which the counter is going to be incremented)
No comments:
Post a Comment