-9

Write a C function which accepts a positive integer, n, and returns 2^n. State any assumptions made.

So is this correct....??

#include<math.h>
double power(int x)
 {
     int i,pow,n, ans;
     ans=1;


     printf ("Enter the number and power:");
     scanf ("%d%d", &pow, &n);

     for(i=1;i<=pow; i++)
     {
       ans = ans *n                    
        return pow(2,n);
      }




    int main ()
    {
       int x, y,c;
       c=pow(x,y);

       printf("%d to the power %d is %d",n,pow,ans);
       getch();

}

stephy
  • 1
  • 1
  • 1
    already tried what? there is simply a function prototype but no actual code to perform the task... what have you tried so far? SO is not about us doing your homework... – NirMH May 14 '14 at 06:22

1 Answers1

0

If I understand, what you want is simply to do 2^n. p^n will never exists.

 #include <math.h>
    double two_pow_n(int n){
      return pow(2, n);
    }
JumpIfBelow
  • 53
  • 2
  • 11