zegulas
Traceur
#include<iostream.h>
int main()
{
int n;
double m;
char a;
void power(double,int);
cout<<"Enter the number"<<endl;
cin>>m;
cout<<"You want to raise this number to power 2. Right?";
cout<<endl<<"if YES, enter Y else enter N"<<endl;
cin>>a;
if(a=='Y')
{
n=1;
}
else
{
cout<<"Enter the power to which you want to raise"<<m<<endl;
cin>>n;
}
power(m,n);
}
void power(double m,int n)
{
double x=1;
if(n==1)
{
x=m*m;
}
else
{
for(i=0;i<n;i++)
{
x*=m;
}
}
if(n==1)
{
cout<<"the given number: "<<m;
cout<<"raised to power 2 gives the value: "<<x<<endl;
}
else
{
cout<<"The given number: "<<m;
cout<<"raised to power: "<<n;
cout<<"gives the value: "<<x<<endl;
}
}
I attended my 1st C++ lecture yesterday and learnt this program, after trying to compile & run it in Dev C++, it just runs n goes away in fraction of a second, I don't even know if it shows correct answer or not!