Thursday, 27 October 2011

C program to calculate x^y without using pow() function

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

14 comments:

  1. We can use recursion to find write a C program to find power of a number using divide and conquer c programming techniques..
    Let 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;

    ReplyDelete

  2. Very 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

    ReplyDelete
  3. please prefer to www.rytservices.com

    ReplyDelete
  4. this is partially correct it doesnt deals with float powers

    ReplyDelete
  5. make the same program without using multiply operator and pow() function

    ReplyDelete
  6. Why u use temporary variable t we can use x also directly

    ReplyDelete
  7. Program to find power without using power function but using function

    ReplyDelete
  8. what is the program for float to the power float without using pow() funciton

    ReplyDelete