C Program To Raise Number To Power
Learn How To Raise Number To Power in C Programming Language. It is important that we should know How A For Loop Works before getting further with this C Program Code Tutorial.
Example
Base Number = 3
Power = 2
Output: 32 = 9
Method 1: Raise A Number To Power in C Programming with While Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<stdio.h> int main() { int base_num, pow_num, value = 1; printf("\nEnter the Number:\t"); scanf("%d", &base_num); printf("\nEnter the Power:\t"); scanf("%d", &pow_num); while(pow_num != 0) { value = value * base_num; pow_num--; } printf("\nResult = %d\n", value); return 0; } |
Also Read: C Program To Raise A Integer To Power using Recursion Method
Method 2: C Program To Raise Number To Positive Power using For Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<stdio.h> int main() { int base_num, pow_num, value = 1; printf("\nEnter the Number:\t"); scanf("%d", &base_num); printf("\nEnter the Power:\t"); scanf("%d", &pow_num); for(value = 1; pow_num != 0; pow_num--) { value = value * base_num; } printf("\nResult = %d\n", value); return 0; } |
Method 3: C Program To Raise an Integer To Power using Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<stdio.h> int raise_number(int power, int base) { int value = 1; while(power != 0) { value = value * base; power--; } return value; } int main() { int pow_num, base_num; printf("\nEnter the Number:\t"); scanf("%d", &base_num); printf("\nEnter the Power:\t"); scanf("%d", &pow_num); printf("\nResult = %d\n", raise_number(pow_num, base_num)); return 0; } |
Output

In case you get any Compilation Errors with this C Program To Raise Number a Power or if you have any doubt about it, let us know about it in the Comment Section below.
I liked the conversion of For Loop into While Loop. Can we raise number to integer in C using Recursion?