Sunday, 8 November 2015

Write a function power that computes x raised to the power y for integer x and y and returns double type value.

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
    int x,y;
    double power();
    clrscr();

    printf("Enter value of x : ");
    scanf("%d",&x);
    printf("Enter value of y : ");
    scanf("%d",&y);

    printf("%d to power %d is = %f\n",x,y,power(x,y));
    getch();
}
double power(x,y)
int x,y;
{
    double p;
    p=1.0;
    if(y>=0)
       while(y--)
           p*=x;
    elsewhile(y++)
           p/=x;
    return(p);
}

No comments:

Post a Comment