Click here to Skip to main content
15,883,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone I'm having a small issue with my program here. For my output for this program I'm getting 0,000000 ^ 0.00000000 = a random negative number. Any help with this program would be appreciated. Also as a side note I'm having to compile this with a -lm because with out it I get an
VB
/tmp/ccwyE4mh.o: In function `power':
a10p2.c:(.text+0xb2): undefined reference to `pow'
collect2: error: ld returned 1 exit status




XML
#include <stdio.h>
#include <math.h>
double power(double x, double n);
int main(void)
{
int x,n;
printf("insert base: ");
scanf("%lf",&x);
printf("insert power: ");
scanf("%lf",&n);
double powerresult = power(x,n);
printf("%lf ^ %lf = %lf\n");
return 0;
}
double power(double x, double y)
{
double result;
result = pow(x,y);
return result;
Posted
Comments
Sergey Alexandrovich Kryukov 13-Apr-15 23:47pm    
There is no a single ^ operator in your code sample. What are you talking about?
—SA

1 solution

Mian issue is you have provided no input for printf. Which compiler are you using?

https://msdn.microsoft.com/en-us/library/wc7014hz.aspx[^]

C++
#include <stdio.h>
#include <math.h>

double power(double x, double n);

int main(void)
{
	int x,n;
	printf("insert base: ");
	scanf("%ld",&x);

	printf("insert power: ");
	scanf("%ld",&n);

	printf("%ld ^ %ld = %lf\n", x, n, power(x,n));

	return 0;
}

double power(double x, double y)
{

	return pow(x,y);

}
 
Share this answer
 
v4
Comments
sparton07sev 13-Apr-15 23:36pm    
I'm using putty to write all my programs.
[no name] 13-Apr-15 23:49pm    
That's a terminal program. You are running a compiler from there.
sparton07sev 13-Apr-15 23:40pm    
Also thanks for helping.
[no name] 13-Apr-15 23:50pm    
Any time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900