Write a C program to calculate x^y without using standard library function.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,i,ans;//ans=value of x^y
//Accept values of x and y
printf("\nEnter value of x : ");
scanf("%d",&x);
printf("\nEnter value of y : ");
scanf("%d",&y);
ans=1; //initialize ans=1
//calclate x^y
for(i=1;i<=y;i++)
{
ans=ans*x;
}
//printing result
printf("\nvalue of x^y : %d",ans);
getch();
}
0 Comments