What is your:
-OS
-compiler
-text editor or whatever
What is your:
-OS
-compiler
-text editor or whatever
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
vista home premium
cygwin compiler
notepad as editor
if worse comes to worse can you help me with any other part of the code? will the output be correct? if not what do i need to do to fix it?
i can try to compile it tomorrow morning on the unix system before class.
Last edited by hockey1; 02-15-2009 at 09:29 PM.
If this is what you wanted to see:
Then this will work:Code:a=5.600000, b=0.500000, c=1.000000 result=28.706667 a=7.300000, b=3.000000, c=3.300000 result=10.082542 a=6.000000, b=8.000000, c=6.500000 result=-91.487930 a=12.200000, b=10.300000, c=6.600000 result=-58.818336 a=2.000000, b=4.100000, c=8.400000 result=-200.039963 a=3.200000, b=4.300000, c=15.300000 result=-683.492065
Hopefully you can spot the differences; the first element of an array is 0, not 1. And the precision is slightly better if you actually use powf().Code:#include <stdio.h> #include <math.h> #define CONSTANT 5.9 int main () { float a[7] = { 5.6, 7.3, 6, 12.2, 2, 3.2 }; float b[7] = { 0.5, 3, 8, 10.3, 4.1, 4.3 }; float c[7] = { 1, 3.3, 6.5, 6.6, 8.4, 15.3 }; float result; int i; for ( i = 0; i < 6; ++i ){ result = CONSTANT*a[i]-2/(b[i]+c[i])-3*powf(c[i],2); printf ("a=%f, b=%f, c=%f\nresult=%f\n", a[i], b[i], c[i], result); } return 0; }
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
damn looks like i was close . thanks though, i really appreciate it and that output was exactly what i was looking for.
i compiled the code you edited and it still came up with the _flock_ file errors so im guessing things will work on the unix system. hopefully :/
anyways, again for the millionth time...THANKYOU u really know your stuff.
you do not need pow function to calculare squares.
just use
Code:c[i]* c[i]
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Notepad sometimes save files in Unicode, with the Unicode byte-order marker (see here). This may be the cause of your odd characters. I would suggest using a different editor, one that will help you via syntax coloring and the like. For example, notepad++, SciTE, Crimson Editor. If you're used to Unix editors vim and emacs are also available for Windows.notepad as editor
And vart's right...if you're only doing squares, it's probably overkill to bring in the math library.
ok sounds good, i found out why i got all the errors.
i didnt include a -lm when i compiled it. should have looked like this...
gcc assignment.c -lm