WRITE A C PROGRAM TO CALCULATE X^Y WITHOUT USING POW() FUNCTION
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,i,r=1,t;
printf("Enter a number:");
scanf("%d",&x);
printf("Enter the power:");
scanf("%d",&y);
for(i=1;i<=y;i++)
{
t=x;
r=r*t;
}
printf("Result:%d",r);
getch();
}
Output:
Enter a number:5
Enter the power:3
Result:125
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,i,r=1,t;
printf("Enter a number:");
scanf("%d",&x);
printf("Enter the power:");
scanf("%d",&y);
for(i=1;i<=y;i++)
{
t=x;
r=r*t;
}
printf("Result:%d",r);
getch();
}
Output:
Enter a number:5
Enter the power:3
Result:125
We can use recursion to find write a C program to find power of a number using divide and conquer c programming techniques..
ReplyDeleteLet power(a, b) means ab.
If b is even : power(a, b) = power(a, b/2)*power(a, b/2);
if b is odd : power(a, b) = power(a, b/2)*power(a, b/2)*a;
ReplyDeleteVery informative article.Thank you author for posting this kind of article .
http://www.wikitechy.com/view-article/power-function-in-c-with-example-and-explanation
Both are really good,
Cheers,
Venkat
sasas
ReplyDeleteplease prefer to www.rytservices.com
ReplyDeleteHow to draw its flowchart
ReplyDeletethis is partially correct it doesnt deals with float powers
ReplyDeletejust change int to float
Deletebut it not work properly
Deletemake the same program without using multiply operator and pow() function
ReplyDeleteWhy u use temporary variable t we can use x also directly
ReplyDeleteProgram to find power without using power function but using function
ReplyDeleteGood
ReplyDeleteBut t variable extra r=r*x;
ReplyDeletewhat is the program for float to the power float without using pow() funciton
ReplyDelete