Special Programs in C − Calculating Power of an Integer

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 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 TH-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

  • @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

  • @mrunalshende1663
    @mrunalshende1663 4 ปีที่แล้ว +18

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

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

  • @gopichowdary2040
    @gopichowdary2040 6 ปีที่แล้ว +5

    As usually another awesome video sir...

  • @mayankjadhav4509
    @mayankjadhav4509 6 ปีที่แล้ว +4

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

  • @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

  • @dn2358
    @dn2358 6 ปีที่แล้ว +3

    Really great explaination...

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

  • @upendrakushwaha5123
    @upendrakushwaha5123 6 ปีที่แล้ว +1

    Nice explanation

  • @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:)

  • @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

    • @Jkt61205
      @Jkt61205 4 ปีที่แล้ว

      you are right

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

  • @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)

  • @hlmeyknebrayebgdi8350
    @hlmeyknebrayebgdi8350 3 ปีที่แล้ว

    U are an amazing one thanks for ur support

  • @vaibhuuanand
    @vaibhuuanand 6 ปีที่แล้ว +2

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

  • @stacyhackney6100
    @stacyhackney6100 2 ปีที่แล้ว

    Thank you

  • @ajini.p
    @ajini.p 5 ปีที่แล้ว

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

  • @7949RAJ
    @7949RAJ 5 ปีที่แล้ว +2

    Hi sir, Will this code work for fractional powers?

  • @ehabtalaat10
    @ehabtalaat10 6 ปีที่แล้ว +1

    make avideo about pointers and structure in c program

  • @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

  • @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

  • @true4189
    @true4189 4 ปีที่แล้ว

    Thank u

  • @kakabraza8869
    @kakabraza8869 ปีที่แล้ว

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

  • @jacklaughter1219
    @jacklaughter1219 4 ปีที่แล้ว +1

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

  • @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. 🙃

  • @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

  • @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 3 ปีที่แล้ว

      Bro Spoon feeding is not good!!!

  • @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

  • @salmanmajid3936
    @salmanmajid3936 8 หลายเดือนก่อน

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

  • @onyekachikelvin3570
    @onyekachikelvin3570 ปีที่แล้ว

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

  • @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

  • @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

  • @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

  • @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