Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 19th, 2012, 07:20 AM
 Upendra Pratap
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", &degree);
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

#2
December 19th, 2012, 07:49 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,259
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 47 m 13 sec
Reputation Power: 1827
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.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

#3
December 19th, 2012, 10:21 AM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,858
Time spent in forums: 3 Months 1 Day 5 h 51 m 7 sec
Reputation Power: 2199
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.

#4
December 19th, 2012, 12:55 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,536
Time spent in forums: 2 Months 3 Days 6 h 2 m 28 sec
Reputation Power: 4106
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

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Floating number error