c - 1.7 function of K&D book . How it calculate 2^0 when p is declared as 1 -
#include<stdio.h> int power(int m,int n); main() { int i; for(i=0;i<10;i++) printf("%d %d %d\n",i,power(2,i),power(-3,i)); return 0; } int power(int base,int n) { int i,p; p=1; // doubt in line for(i=1;i<=n;++i) p=p*base; return p; }
when p declared 1 . how calculate value 2^0.yet i'm beginner of c programming can't able logic behind this.and doubt in function program how works 2^0 when p=1.thanks replay..
i'm assuming 2^0 mean inputs function power
2 , 0.
in case, n = 0
, , loop doesn't run because i = 1
greater 0. in case, function returns 1 because initialized p
1, , loop didn't modify it.
Comments
Post a Comment