Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ok, so essentially I have to write a basic program in C-- where x^y outputs a re

ID: 440535 • Letter: O

Question

Ok, so essentially I have to write a basic program in C-- where x^y outputs a result (z) and I'm not really sure how to put it into an acceptable form that the computer can read I have all the information I think, but i just dont know how to put it together - So I create 3 variables - x,y and z (%x^y = z) - y HAS to be an integer, if y is not integer, then program says "Error, y needs to be integer" - z = x multiplied y-times (So if y = 2, then z = x*x, or if y = 3, then z = x*x*x) - If y = 0, then z = 1 - Else if y > 0 then z = x^y - Else if y < 0 then z = 1/x^y Also if I'm missing any possible scenario, do you mind telling me? I think I got them all

Explanation / Answer

float power(){

        int x,y,z,i=0;

        scanf("%d%d",&x,&y);

       if(IsInt(y)){

     if(y>0)

         for(i=0;i<y;i++)

                z *= x ;

          if(y==0)

               z = 1 ;

          if(y<0){

              for(i=0;i<y;i++)

                   z *= x ;

                   z = 1/z ;

       }

       }

       else{

   printf("Error, y needs to be integer");

   return 0 ;

        }

    return z ;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote