Calculate x to the power y - Exponentiation in C

Write a C program to calculate the x to the power y without using standard function.

Solution:

#include<stdio.h>
void power(int x,int y)
{
     int ans = 1, i;
     for(i=1; i<=y; i++)
          ans = ans*x;
     printf("  %d^%d : %d", x, y, ans);
}
int main()
{
     int x,y;
     printf("/*Calcualate : x^y*/\n");
     printf("\nEnter Value of x : ");
     scanf("%d", &x);
     printf("\nEnter Value of y : ");
     scanf("%d", &y);
     printf("----------------------\n");
     power(x,y);
     return 0;
}


Output:

exponentiation