C Program to Find Power of a number using for Loop

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.


	#include 
	int main()
	{
		int a, b;
		long  pnum = 1;
		printf("Enter the value of A :");
		scanf("%d",&a);
		printf("Enter the value of B :");
		scanf("%d",&b);
		if (b > 0)
		{
			for (int i = b; i>0; i--)
			{
				pnum = pnum * a;
				
			}
		}
		else if(b =0){
			pnum=1;
		}
		
		printf("%d Raised to the Power of %d is %d",a,b ,pnum);
	}
	Enter the value of A :7
	Enter the value of B :2
	7 Raised to the Power of 2 is 49
Compile and Run Online