C++ Program of (a) power b without using any builtin functions
Program Body
#include< iostream >
#include< conio.h >
using namespace std;
int main(){
int ex,re,num,n;
const int z=0;
cin>>num;
cin>>ex;
if(num>0&&ex>0){
re=numnum;
for(n=2;n<ex;n++){
re=renum;
}
cout<<re;
}else if(num<0&&ex>0){
re=numnum;
for(n=2;n<ex;n++){
re=renum;
}
cout<<re;
}
else if(num>0&&ex<0){
cout<<"0.";
ex=-ex;
if(num>9&&num<100){
for(n=2;n<ex;n++){
cout<<z;
}
cout<<num;
}else if(num>0&&num<10){
for(n=1;n<ex;n++){
cout<<z;
}
cout<<num;
}else if(num>99&&num<1000){
for(n=3;n<ex;n++){
cout<<z;
}
cout<<num;
}
}else if(num<0&&ex<0){
cout<<"- 0.";
ex=-ex;
for(n=1;n<ex;n++){
cout<<z;
}
cout<<-(num);
}
else if(ex==0){
cout<<1;
}
else {
cout<<"Invalid exponent expression"<<endl;
}
getch();
return 0;
}
its really a great logic in this program
I am thankful
Can you explain it in details?
good work bro...
amazing post
Thank you
*
disappears…)conio.h
is a Microsoft Windows thing, avoid that for general C++ code; moreover it is used just to add a pause hit-a-key-to-continue; that's a problem I've seen often when students don't know how to run a program from the console (Windows open a console of its own for the text output of the program, but it is closed as the program ends, hence the “need” to pause) — very rookie! Don't do it: run the program from the console instead.main
.2
and-2
as input, it gives0.02
as result, instead of0.25
(1/4). If the inputs are3
and100
, the output is-818408495
(check for overflow…)