Path: utzoo!attcan!uunet!pilchuck!ssc!mcgp1!brat!donn From: donn@brat.UUCP (Donn Pedro) Newsgroups: comp.lang.c Subject: Re: # to the nth power Message-ID: <345@brat.UUCP> Date: 4 Nov 90 16:42:26 GMT References: <90305.005050CJH101@psuvm.psu.edu> Organization: Tandemonium, Kent, WA Lines: 37 In article <90305.005050CJH101@psuvm.psu.edu>, CJH101@psuvm.psu.edu (Carl J. Hixon) writes: > I appologize for bothering you computer wizards with such an elementary > question but, I'm floundering. Why am I unable to find an opperator which > raises a number to a power. (The fortran equivalent of x**n) Is there such > an opporator or do I need to write my own function? It seems like a terrible > oversite to me that such a common operation was overlooked. > > Any help would be greatly appreciated! I'm not sure I could even write the > function, I'm currently writing my first C program ever... > > Thankyou, > > Carl Straight from K&R. Page 25. /*power: raise base to n-th power; n>= 0 */ int power(int base, int n) { int i, p; p = 1; for (i = 1; i <= n; ++i) p = p * base; return p; } This is written as a function. On page 24 you will find the same stuff in a main(). Donn F Pedro ....................a.k.a. uunet!nwnexus!mcgp1!brat!donn else: {the known world}!uunet!nwnexus!mcgp1!brat!donn