Monday, September 1, 2014

finding value of x raise to power y


Write a program that asks the user to input two numbers x and y. the program calculates x
raise to power y using loop and display the result.

Code

#include<stdio.h>
int main()
{
int x,y,p,i;
printf("Enter two numbers = ");
scanf("%d%d",&x,&y);
p=1;
i=1;
while(i<=y)
{
p=p*x;
i=i+1;
}
printf("Answer= %d\n",p);
system("pause");
return 0;
}

Sample Output


No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact