The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Floating number error
Discuss Floating number error in the C Programming forum on Dev Shed. Floating number error C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 19th, 2012, 06:20 AM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 9
Time spent in forums: 4 h 17 m 58 sec
Reputation Power: 0
|
|
|
Floating number error
can anyone find the mistake in the following code:
#include<stdio.h>
#include<math.h>
#include<conio.h>
int degree;
float fun01coff[100];
float fun02coff[100];
void main()
{
printf(" enter the degree of equation\n\n");
scanf("\n%d", °ree);
printf(" enter the coeffiecients\n\n");
int i =0;
for(i =0; i<= degree; i++)
{
scanf("\n %d", &fun01coff[i]);
}
int deg = degree;
float res = 0.0;
for( i = 0; i<= deg; i++)
{
printf("\n printing value of i = %d",i);
res = res + (float)(fun01coff[i]*(pow(0,deg-i)));
printf(" \n\n answer = %f", res);
}
}
i wanted to find the value of polynomial for some value of x such as x = 0
|

December 19th, 2012, 06:49 AM
|
 |
Contributed User
|
|
|
|
|
Well the first mistake is that you've been here for nearly a year, but you're still posting code without using [code][/code] tags.
So consider your post as being ignored for the moment.
|

December 19th, 2012, 09:21 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
Also, just exactly why do you think that there's any mistake in your code?
IOW, what are the symptoms that lead you to believe that there's a mistake? We cannot read your mind and we don't have time to play stupid guessing games.
|

December 19th, 2012, 11:55 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
This line is wrong:
Code:
scanf("\n %d", &fun01coff[i]);
You've declared fun01coff as float. You shouldn't be using %d to read into it. I'll leave it to you to figure out what the correct format string should be, as a homework assignment  .
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|