找到力量

时间:2014-05-14 06:20:38

标签: c

写一个接受正整数n的C函数,并返回2 ^ n。陈述任何假设。

这是正确的吗?? ??

#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();

}

1 个答案:

答案 0 :(得分:0)

如果我理解,你想要的只是做2 ^ n。 p ^ n永远不会存在。

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