Pages

Tuesday, November 10, 2015

C program to calculate a^b (power)

//This program calculates the power of 2 numbers using for loop.

Program

#include<stdio.h>
void main()
{
 int a,b,i,pow;
 printf("Enter value of a: ");
 scanf("%d",&a);
 printf("Enter value of b: ");
 scanf("%d",&b);
 pow=1;

 for(i=1;i<=b;i++)
 {
  pow=pow*a;
 }

 printf("a^b = %d",pow);

}

Output
Enter value of a: 2
Enter value of b: 5

a^b = 32

No comments:

Post a Comment