What a coincidence today teacher said to me solve this question as homework And after coming home when I open UA-cam and watching comedy videos for mind fresh when I scrolled down then saw that this video is recommended me I am very happy. My teacher said me write program only positive power but I also know how to find out power of negative. Thank you so much
int main() { int base,exp,power; printf("Enter the base: "); scanf("%d",&base); printf("Enter the exp: "); scanf("%d",&exp); power = pow(base,exp); printf("The value is: %d",power); return 0; }
use double data instead of int for power1 variable because int has more range for those people who want the power for large base and exponent if you want max power for extremely large base and exponent use long double the order int
firstly thank you for your effort , you deserve all the best i think one condition is missed " x to the power of zero " i tried to find it out #include int main() { int power =1,base, exponent,expo ; double power1 = 1.0; printf("enter base "); scanf_s("%d",&base); printf("enter exponent "); scanf_s("%d",&exponent); expo = exponent; if (exponent >= 0) { exponent = exponent + 1; for (exponent; exponent != 0; exponent--) { power = base * power ; } power = power / base; printf("%d to the power of %d equals %d",base , expo, power); } else { for (exponent; exponent != 0; exponent++) { power1 = (1.0 / base) * power1; } printf("%d to the power of %d equals %.10f ", base, expo, power1); } }
#include int main(){ int base,expo,p=1; printf("Base "); scanf("%d",&base); printf("Enter expo "); scanf("%d",&expo); if(expo>0){ while(expo!=0){ p=p*base; expo--; } } printf("%d",p); } it can also be done by this method:)
This is my solution to this exercise: #include int main() { int base, exponent, result, n, i; result = 1; printf(" Please enter the base: "); scanf("%d", &base); printf("Please enter the exposant: "); scanf("%d", &exponent); i = 0; n =exponent; if ( exponent >= 0) { while(i
Why did this man get only few likes...this channel worth of million likes.. Oh..I forgot it..he loves his passion.. when ever a girl post a tik tok video she will get million likes 😅😅 Nb: please avoid the grammer mistakes
There's a problem with this code. If the the base is *negative* and the exponent is *negative* _and_ *pair.* The result will be positive which is incorrect. I traced why this happens but can't find the adjustments to make.
There is missing case what if exponent become zero Ur not given that condition please check That condition is if exponent equal to zero than output is one
sir plz plz plz complete subject of analog electronics,signals and systems sir....preparing for gate2019 sir....plz plz plz plz sir waitinng for ur lecturers.....when it possibe when will it be completed sir ... plzz sir reply sir ....
Is it okay to do like this //author=sahil //purpose=to fine the power of enterd digit #include int main() { double res = 1.0; int i, num, power, result = 1, pwr; printf("enter number: "); scanf("%d", &num); printf("enter the poewr: "); scanf("%d", &power); if (power > 0) { for (i = 0; i < power; i++) { result = result * num; } printf(" %d to the power %d is %d", num, power, result); } if (power < 0) { pwr = -power; for (i = 0; i < pwr; i++) { res = res * (1.0 / num); } printf("%dto the power %d is %.10f", num, power, res); } return 0; }
What a coincidence today teacher said to me solve this question as homework
And after coming home when I open UA-cam and watching comedy videos for mind fresh when I scrolled down then saw that this video is recommended me
I am very happy.
My teacher said me write program only positive power but I also know how to find out power of negative.
Thank you so much
int main()
{
int base,exp,power;
printf("Enter the base: ");
scanf("%d",&base);
printf("Enter the exp: ");
scanf("%d",&exp);
power = pow(base,exp);
printf("The value is: %d",power);
return 0;
}
what if we just use already defined power function ""result=pow(x,y)"==x^y
^ is XNOR operation
You are the best teacher ever ana ever no one can beat you in this field keep rock sir all the best
use double data instead of int for power1 variable because int has more range
for those people who want the power for large base and exponent
if you want max power for extremely large base and exponent
use long double
the order int
As usually another awesome video sir...
firstly
thank you for your effort , you deserve all the best
i think one condition is missed " x to the power of zero "
i tried to find it out
#include
int main()
{
int power =1,base, exponent,expo ;
double power1 = 1.0;
printf("enter base
");
scanf_s("%d",&base);
printf("enter exponent
");
scanf_s("%d",&exponent);
expo = exponent;
if (exponent >= 0)
{
exponent = exponent + 1;
for (exponent; exponent != 0; exponent--)
{
power = base * power ;
}
power = power / base;
printf("%d to the power of %d equals %d",base , expo, power);
}
else
{
for (exponent; exponent != 0; exponent++)
{
power1 = (1.0 / base) * power1;
}
printf("%d to the power of %d equals %.10f ", base, expo, power1);
}
}
#include
int main(){
int base,expo,p=1;
printf("Base
");
scanf("%d",&base);
printf("Enter expo
");
scanf("%d",&expo);
if(expo>0){
while(expo!=0){
p=p*base;
expo--;
}
}
printf("%d",p);
}
it can also be done by this method:)
Really great explaination...
Thank you Neso Academy I was looking for that...😊
You could have simply used pow(a,b), where a is base and b is the exponent.
@@nesoacademy I have realised my mistake and I owe you an apology. Keep on making good videos like this one. May God bless you.
This is my solution to this exercise:
#include
int main()
{
int base, exponent, result, n, i;
result = 1;
printf(" Please enter the base: ");
scanf("%d", &base);
printf("Please enter the exposant: ");
scanf("%d", &exponent);
i = 0;
n =exponent;
if ( exponent >= 0)
{
while(i
Please upload some videos for 'Design and Analysis of Algorithms(DAA)'.
Sir , if exponent ==0, then the result would be simply 1 for all the cases..... should we not add it to the code as well?
It is already a part of the code (in else part)
Nice explanation
U are an amazing one thanks for ur support
Hi sir, Will this code work for fractional powers?
Thank you
sir Plz..... Tell me How should I think like U bz you are very clear in programming!
Means How do you think programming!
good question. i wolud like to think like programmer too. how to achieve it?
Mark Mark by practice and applies logic.
Keep practicing...
Why did this man get only few likes...this channel worth of million likes..
Oh..I forgot it..he loves his passion.. when ever a girl post a tik tok video she will get million likes 😅😅
Nb: please avoid the grammer mistakes
you are right
What if i include then use the power function pow(base,exponent)
make avideo about pointers and structure in c program
Sir if exponent=0 then will these code work for it for ex.base=2 and exponent=0
Create another if statement and give expo==0 printf("1"); something like this and you get 1 if exponential is 0 in any case
Thank you!
what about float exponentials? can u write a program for that too pls??
Thank u
This code doesn't gives expected output for base=255, expo=4, for this case the result coming is -66716671, while it should be 4228250625
use double data instead of int for power1 variable because int has less range
Sir you have not given the conditions when exponent is equal to zero and when base=0..
sir its showing negative value when i entered base and expo as 12 12
There's a problem with this code. If the the base is *negative* and the exponent is *negative* _and_ *pair.* The result will be positive which is incorrect. I traced why this happens but can't find the adjustments to make.
SOLVED: just add this before the last printf statement:
if((expo%2 == 0) && (base < 0))
powerl = -powerl;
If the the base is negative number and the exponent is negative and even number the result is positive. 🙃
There is missing case what if exponent become zero
Ur not given that condition please check
That condition is if exponent equal to zero than output is one
Bro Spoon feeding is not good!!!
"How am I supposed to write programs like this on my own?"
sir plz plz plz complete subject of analog electronics,signals and systems sir....preparing for gate2019 sir....plz plz plz plz sir waitinng for ur lecturers.....when it possibe when will it be completed sir ... plzz sir reply sir ....
I did not understand why its printing 3 in expo as exponent is 0 (expo=exponent) can any one help
Can I help
#include
int main()
{
int m,n,i,val=1;
printf("enter number and power
");
scanf("%d %d",&m,&n);
while(i
initially "i" will be assigned a garbage value
I'm actually just seeing all this for the very first time.... How can I cope with no basics at all
And no prior knowledge to any of this
What happens first bit is 0
For power 0, we should add one more case.🙄
Is it okay to do like this
//author=sahil
//purpose=to fine the power of enterd digit
#include
int main()
{
double res = 1.0;
int i, num, power, result = 1, pwr;
printf("enter number:
");
scanf("%d", &num);
printf("enter the poewr:
");
scanf("%d", &power);
if (power > 0)
{
for (i = 0; i < power; i++)
{
result = result * num;
}
printf(" %d to the power %d is %d", num, power, result);
}
if (power < 0)
{
pwr = -power;
for (i = 0; i < pwr; i++)
{
res = res * (1.0 / num);
}
printf("%dto the power %d is %.10f", num, power, res);
}
return 0;
}
Exp 0 then fail the program
The Simplest Method..
#include
int main()
{
int b,e;
printf("Enter Base:");
scanf("%d",&b);
printf("Enter Exponent:");
scanf("%d",&e);
if(e>0)
{
int ans= pow(b,e);
printf("
Answer:%d",ans);
}
else if(e