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 [co[u][/u]de][/co[u][/u]de] tags >>

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

Recommended Answers

All 4 Replies

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

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.