Power function without loops in C Language

Power function without Loops ( a^b ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/********** a power b program in C ***************/ #include<stdio.h> int main() { Â Â Â Â int a, b, result; Â Â Â Â Â printf("Enter two values : "); Â Â Â Â scanf("%d%d", &a, &b); Â Â Â Â Â result=a; Â Label: Â Â Â Â if(b>1) Â Â Â Â { Â Â Â Â Â Â Â Â result = result * a; Â Â Â Â Â Â Â Â b--; Â Â Â Â Â Â Â Â goto Label; Â Â Â Â } Â Â Â Â printf("The value of %d Power %d is %d \n",a, b, result); } |
Program Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
venkey@venkey$ gcc a_power_b.c venkey@venkey$ ./a.out Enter two values : 10 2 The value of 10 Power 2 is 100 venkey@venkey$ ./a.out Enter two values : 2 10 The value of 2 Power 10 is 1024 venkey@venkey$ ./a.out Enter two values : 5 3 The value of 5 Power 3 is 125 venkey@venkey$ ./a.out Enter two values : 13 3 The value of 13 Power 3 is 2197 venkey@venkey$ ./a.out Enter two values : 8 4 The value of 8 Power 4 is 4096 venkey@venkey$Â Â |
2 Responses
[…] C Program to find power of number without Loops […]
[…] C Program to find power of number without Loops […]