Using while loops find the factorials of odd numbers between
Using while loops find the factorials of odd numbers between 13-1 and even numbers between 1-14 Find the squares of all numbers between +14 – 14. Design your square function Find cubes of all numbers between -14 to + 14. Design your cube functions Find 5th power of all numbers between -9 to + 9 using the above square/cube function
Solution
#include \"stdafx.h\"
using namespace std;
//-------------functions for cube and square----------
// function which return cube of number
double square(int number)
{
double t= number*number;
return t;
}
// function which return cube of number
double cube(int number)
{
double t= number*number*number;
return t;
}
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
cout<<\" factorial of odd numbers between 13-1\"<<endl;
// factorial of odd numbers between 13-1
for(i=13;i>=1;i--)
{
int temp=i;
if(temp%2!=0)
{
int factorial = 1;
while (temp>0)
{
factorial = factorial * temp ;
temp--;
}
cout<<\"Factorial of Number: \"<<i<< \"\\t is \"<<\"\\t\"<<factorial<<endl;
}
}
cout<<\" factorial of even numbers between 1-14\"<<endl;
for(i=1;i<=14;i++)
{
int temp=i;
if(temp%2==0)
{
int factorial = 1;
while (temp>0)
{
factorial = factorial * temp ;
temp--;
}
cout<<\"Factorial of Number: \"<<i<< \"\\t is \"<<\"\\t\"<<factorial<<endl;
}
}
cout<<\"squares of number between +14 to -14\"<<endl;
for(i=14; i>=-14;i--)
{
cout<<\"Square of Number : \"<<i<<\"\\t is\\t\"<<square(i)<<endl;
}
cout<<\"cubes of number between -14 to +14\"<<endl;
for(i= -14; i<=14;i++)
{
cout<<\"cubes of Number : \"<<i<<\"\\t is\\t\"<<cube(i)<<endl;
}
cout<<\"5th power of number between -9 to +9\"<<endl;
for(i= -9; i<=9;i++)
{
cout<<\"5th power of Number : \"<<i<<\"\\t is\\t\"<<cube(i)*square(i)<<endl;
}
getch();
return 0;
}

