//27-11-2014
//Ahmad Furqan Attari
//P5.7
#include <iostream>
#include "conio.h"
using namespace std;
double power(double num, int p=2)
{
double ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
int power(char num, int p = 2)
{
int ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
int power(int num, int p = 2)
{
int ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
long power(long num, int p = 2)
{
long ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
float power(float num, int p = 2)
{
float ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
void main(void)
{
char var_char=6;
int var_int=5;
long var_long = 7;
float var_float = 3;
double var_double = 9;
cout << "1 " << power(var_char,5)<<endl;
cout << "2 " << power(var_int, 5) << endl;
cout << "3 " << power(var_long, 5) << endl;
cout << "4 " << power(var_float, 5) << endl;
cout << "5 " << power(var_double, 5) << endl;
_getch();
}
//Ahmad Furqan Attari
//P5.7
#include <iostream>
#include "conio.h"
using namespace std;
double power(double num, int p=2)
{
double ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
int power(char num, int p = 2)
{
int ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
int power(int num, int p = 2)
{
int ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
long power(long num, int p = 2)
{
long ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
float power(float num, int p = 2)
{
float ans = 1;
for (int i = 0; i<p; i++)
{
ans *= num;
}
return ans;
}
void main(void)
{
char var_char=6;
int var_int=5;
long var_long = 7;
float var_float = 3;
double var_double = 9;
cout << "1 " << power(var_char,5)<<endl;
cout << "2 " << power(var_int, 5) << endl;
cout << "3 " << power(var_long, 5) << endl;
cout << "4 " << power(var_float, 5) << endl;
cout << "5 " << power(var_double, 5) << endl;
_getch();
}
No comments:
Post a Comment