954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to perform pow(x,y) where x and y are floats??

Hi everyone,
I am having this problem to define a function which raises a float y eg 3.5 which is not a whole number to the base x.
Heres the code which gives domain error as function pow takes only int values.

//Program to raise a number to power when both are floating nos
#include<stdio.h>
#include<conio.h>
#include<math.h>
void power(float x,float i)
{
 float y;
 y=pow(x,i);
 printf("%d",y);
}

void main()
{
 float x,i;
 printf("Enter any number");
 scanf("%d",&x);
 printf("Enter its power");
 scanf("%d",&i);
 power(x,i);
}


<< moderator edit: added [code][/code] tags >>

I'll be glad if you help me out.
Thanks
:confused:

comwizz
Light Poster
39 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 
SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 
I am having this problem to define a function which raises a float y eg 3.5 which is not a whole number to the base x. Heres the code which gives domain error as function pow takes only int values.

http://www.cplusplus.com/ref/cmath/pow.html

Pow, in the standard C library for mathematical operations, takes two double values by default. You could also look into the powerful powf function.

-Fredric

Daishi
Junior Poster in Training
80 posts since Aug 2005
Reputation Points: 10
Solved Threads: 2
 

I want to run this program in C where I can compute 2^(3.5).Is this possible in C?

comwizz
Light Poster
39 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 
This file:
#include <math.h>
int main(int argc, char *argv[])
{
        printf("%f\n",pow(2., 3.5) );
        return 0;
}
compiled this way (This is unix does not matter)
kcsdev:/home/jmcnama> cc t.c -lm
Gives this result:
kcsdev:/home/jmcnama> a.out
11.313708
jim mcnamara
Junior Poster
180 posts since May 2004
Reputation Points: 62
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You