#include"stdio.h"
#include"math.h"
main()
{int x,n; printf("Enter x and n:"); scanf("%d%d",&x,&n); printf("x power n is %ld\n",power(x,n)); getch();
}
power(x,n)
{long int p; for(p=1;n>0;--n) {p*=x; return(p);
}
正确为:
#include"stdio.h"
#include"math.h"
#include<conio.h >
main()
{int x,n,power(int x,int n);
printf("Enter x and n:");
scanf("%d%d",&x,&n);
printf("x power n is %ld\n",power(x,n));
getch();
} int power(int x,int n)
{ int p;
for(p=1;n>0;n--)//你这边的return(p)不能和for一起循环。。应该放在for外。。
p*=x; return(p);