Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int power1 (int, int);
- int main(void)
- {
- int w, x, n;
- printf("Program calculates the power of integer number for the natural exponent\n\n");
- printf("Give the powered number and the exponent");
- scanf("%d %d", &x ,&n);
- w = power1(x,n);
- printf("Number %d square %d to %d\n ", x, n, w);
- return 0;
- }
- int power1(int x, int n)
- {
- int z,m,y;
- z = x;
- y = 1;
- m = n;
- while(m!=0)
- {
- //x^n = u*z^m and m>0
- if(m%2==1) y= y*z;
- m=m/2;
- z=z*z;
- }
- //y=x^n
- return y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement