Special Programs in C − Calculating Power of an Integer

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 59

  • @info_man
    @info_man 6 років тому +21

    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

  • @aliadel1723
    @aliadel1723 4 роки тому +2

    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;
    }

  • @mrunalshende1663
    @mrunalshende1663 4 роки тому +18

    what if we just use already defined power function ""result=pow(x,y)"==x^y

  • @madhavikatta7346
    @madhavikatta7346 6 років тому +2

    You are the best teacher ever ana ever no one can beat you in this field keep rock sir all the best

  • @TateFireFit
    @TateFireFit 2 роки тому +1

    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

  • @gopichowdary2040
    @gopichowdary2040 6 років тому +5

    As usually another awesome video sir...

  • @mohamedkhawaga8067
    @mohamedkhawaga8067 2 роки тому +1

    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);
    }
    }

  • @PragatiBatra-pd7ul
    @PragatiBatra-pd7ul Рік тому

    #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:)

  • @dn2358
    @dn2358 6 років тому +3

    Really great explaination...

  • @mayankjadhav4509
    @mayankjadhav4509 6 років тому +4

    Thank you Neso Academy I was looking for that...😊

  • @namaychopra7548
    @namaychopra7548 6 років тому +2

    You could have simply used pow(a,b), where a is base and b is the exponent.

    • @namaychopra7548
      @namaychopra7548 6 років тому +1

      @@nesoacademy I have realised my mistake and I owe you an apology. Keep on making good videos like this one. May God bless you.

  • @itsbayahmed
    @itsbayahmed Рік тому

    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

  • @vaibhuuanand
    @vaibhuuanand 6 років тому +2

    Please upload some videos for 'Design and Analysis of Algorithms(DAA)'.

  • @sreemoyeepradhan7707
    @sreemoyeepradhan7707 2 роки тому +2

    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?

    • @harsh_t
      @harsh_t Рік тому +3

      It is already a part of the code (in else part)

  • @upendrakushwaha5123
    @upendrakushwaha5123 6 років тому +1

    Nice explanation

  • @hlmeyknebrayebgdi8350
    @hlmeyknebrayebgdi8350 3 роки тому

    U are an amazing one thanks for ur support

  • @7949RAJ
    @7949RAJ 5 років тому +2

    Hi sir, Will this code work for fractional powers?

  • @stacyhackney6100
    @stacyhackney6100 2 роки тому

    Thank you

  • @ajmalkhaniit
    @ajmalkhaniit 5 років тому +1

    sir Plz..... Tell me How should I think like U bz you are very clear in programming!
    Means How do you think programming!

    • @khalilrin-ju3nm
      @khalilrin-ju3nm 5 років тому

      good question. i wolud like to think like programmer too. how to achieve it?

    • @mahmadtrivedi7890
      @mahmadtrivedi7890 4 роки тому

      Mark Mark by practice and applies logic.

    • @aravindks7636
      @aravindks7636 4 роки тому +2

      Keep practicing...

  • @aravindks7636
    @aravindks7636 4 роки тому +1

    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

  • @kakabraza8869
    @kakabraza8869 Рік тому

    What if i include then use the power function pow(base,exponent)

  • @ehabtalaat7592
    @ehabtalaat7592 6 років тому +1

    make avideo about pointers and structure in c program

  • @harshalkamble7381
    @harshalkamble7381 5 років тому +2

    Sir if exponent=0 then will these code work for it for ex.base=2 and exponent=0

    • @praneethkumar8087
      @praneethkumar8087 3 роки тому

      Create another if statement and give expo==0 printf("1"); something like this and you get 1 if exponential is 0 in any case

  • @ajini.p
    @ajini.p 5 років тому

    Thank you!

  • @jacklaughter1219
    @jacklaughter1219 4 роки тому +1

    what about float exponentials? can u write a program for that too pls??

  • @true4189
    @true4189 4 роки тому

    Thank u

  • @abhijitshaw428
    @abhijitshaw428 3 роки тому

    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

    • @TateFireFit
      @TateFireFit 2 роки тому +1

      use double data instead of int for power1 variable because int has less range

  • @manikantareddy7124
    @manikantareddy7124 4 роки тому

    Sir you have not given the conditions when exponent is equal to zero and when base=0..

  • @atuljoshi8052
    @atuljoshi8052 2 роки тому

    sir its showing negative value when i entered base and expo as 12 12

  • @tariq1028
    @tariq1028 3 роки тому +1

    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.

    • @tariq1028
      @tariq1028 3 роки тому +1

      SOLVED: just add this before the last printf statement:
      if((expo%2 == 0) && (base < 0))
      powerl = -powerl;

    • @slobodantajisic2762
      @slobodantajisic2762 2 роки тому

      If the the base is negative number and the exponent is negative and even number the result is positive. 🙃

  • @palyamprakash8906
    @palyamprakash8906 6 років тому +1

    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

    • @Ayush37262
      @Ayush37262 2 роки тому

      Bro Spoon feeding is not good!!!

  • @salmanmajid3936
    @salmanmajid3936 7 місяців тому

    "How am I supposed to write programs like this on my own?"

  • @jenifergirija8933
    @jenifergirija8933 6 років тому

    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 ....

  • @DACS_VAJAPAYEEGR
    @DACS_VAJAPAYEEGR 3 роки тому

    I did not understand why its printing 3 in expo as exponent is 0 (expo=exponent) can any one help

  • @codingrecharge
    @codingrecharge 2 роки тому

    #include
    int main()
    {
    int m,n,i,val=1;
    printf("enter number and power
    ");
    scanf("%d %d",&m,&n);
    while(i

    • @bujji3573
      @bujji3573 2 роки тому

      initially "i" will be assigned a garbage value

  • @onyekachikelvin3570
    @onyekachikelvin3570 Рік тому

    I'm actually just seeing all this for the very first time.... How can I cope with no basics at all

  • @sajeedkhans7616
    @sajeedkhans7616 Рік тому

    What happens first bit is 0

  • @AyushKumar_-jd1kd
    @AyushKumar_-jd1kd 3 роки тому

    For power 0, we should add one more case.🙄

  • @sahil1307
    @sahil1307 2 роки тому

    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;
    }

  • @addagallanaresh4044
    @addagallanaresh4044 4 роки тому

    Exp 0 then fail the program

  • @sajjadbaba8551
    @sajjadbaba8551 2 роки тому

    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