Could you please put ypur question into the body of your message?
My newreader shows only the 20 to 30 characters of the subject
line and I think other people have the same problem.
#include<stdio.h>
#include<math.h>
#define M_PI 3.14159
Note that on some systems 'M_PI' is a predefined macro.
int main( void )
{
double theta, phi, sinth;
double count;
You should initialize 'count', it's not going to be set to
0 automatically.
s = ((double) 180)/M_PI; /* converting to radiens */
I guess the first problem is here - it looks as if you actually
want
s = M_PI / 180;
i..e set 's' to 1 degree expressed in radians. Otherwise
'sinth' later on starts with a negative value, which you
then use in the calculation of how much you increment 'phi'
and you thus end up with 'phi' going more and more negative
instead of becoming incremented by a positive value.
Note that all your casts to double are unnecessary, the con-
versions will all happen automatically. And then writing
(double) 360
instead of simply
360.0
looks rather strange, to say the least.
incr = 0.5;
theta = (double) 0;
for(theta = incr; theta < (double) 180; theta += incr)
sinth = sin(s *theta);
for(phi = 0; phi < (double) 360 ; phi += incr/ sinth)
count ++;
printf("%f", count);
Your indentation makes it look as if you expect that there
are going to be two nested for loops. But this isn't the
case, what you wrote here are two simple for loops, the
one using 'theta' getting run all through before the se-
cond one with 'phi' getting run only afterwards. C isn't
Python and indentation isn't taken into consideration by
the compiler, it's only for human consumption. You need
to enclose blocks of code in '{' and '}' to tell it what
you want it to do.
Finally, in this line
you should put in a '\n' in the format string, otherwise
there's no linefeed at the end
Regards, Jens