LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2004, 04:09 AM   #1
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Rep: Reputation: 15
Angry Simple C pow() program, strange error


double xpow( double radix, double exp )
{
double result = 1;

while( exp-- )
{
result*= radix;
}

return result;
}


void main()
{

int res2 = xpow( 3, 3 );
double res = xpow( 2, 2 );

printf( " %d \n ", res2 );
printf( " %d \n ", res );
}
----------------------------------------
output:

27
0 <----------------- why???

Help!!
 
Old 06-25-2004, 04:19 AM   #2
Ohmu
LQ Newbie
 
Registered: Jan 2004
Location: Estonia
Distribution: Gentoo
Posts: 20

Rep: Reputation: 0
man 3 printf

printf( " %f \n ", res );

res isn't int... it's double
 
Old 06-25-2004, 04:20 AM   #3
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Original Poster
Rep: Reputation: 15
what a blunder! i haf found it out..was hoping to change it before someone read the post ..dont tell anyone, ok?

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple C program - error with float J_K9 Programming 2 10-24-2005 11:36 AM
A simple program on C++ for the linux with an error. Israfel2000 Programming 4 06-16-2004 06:25 PM
Error for a very simple C program pkashyap Linux - Newbie 2 03-11-2004 10:24 AM
POW, what does it mean to you? Edward78 General 7 08-20-2002 08:10 AM
pow in c acid_kewpie Programming 3 11-12-2001 06:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration