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 […]