1. ## Evaluating sin series

Hello everyone,
I'm having a little trouble solving this question below and I do not know how to proceed further. And I also do not know that what I have done is correct. Can you kindly assist me with this problem.
Here's the question:
http://img10.imageshack.us/img10/5815/questiono.png

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

int main()
{
clrscr();
double x, a, b, c, m, n, i;
printf ("Enter the value of sin x : ");
scanf("%d", &n);
for(i=1 ; i<=n ; i=i+2)
{
a = 2i-1;
b = pow(x,a);
for(j=1 ; j <

}
printf("\nThe calculated value of sin x is ");
printf("%d",m);
getch();
return 0;
}```

2. I just found the answer to this question on the net but I'm unable to run it.
Code:
```#include <stdio.h>
#include <math.h>

double sinEst(double,unsigned);
typedef double (*func)(double,double);
double subtract(double,double);
double factorial(unsigned);

const double PI = 3.1415926535897932384626433832795028841;

typedef struct
{
func f[2];
double k;
} Op_t;

int main(int argc, char *argv[]) {
unsigned n;

if ((argc < 3) ||
(sscanf(argv[1],"%lg",&x) != 1) ||
(sscanf(argv[2],"%u",&n) != 1)) {
printf("usage : %s <x>,<n>\n",argv[0]);
printf(" where <x> = angle for sin estimate, in degrees\n");
printf(" <n> = number of terms, a positive integer\n");
return -1;
}
xRad = x * PI / 180.0;
printf("\nnumber of terms in series = %u",n);
printf("\nestimated sin(%g) = %g",x,sinX);
getch();
return 0;
}

double sinEst(double x, unsigned numTerms) {
double sinX = x;
Op_t op;
unsigned i;

op.f[1] = subtract;
op.k = 3;
for (i = 1; i < numTerms; i++, op.k += 2) {
sinX =
op.f[i%2]( sinX,pow( x,op.k ) /
factorial( (unsigned)op.k ) );
}
getch();
return sinX;
}

double factorial(unsigned n) {
if (n == 1) return n;
return n * factorial(n-1);
}
double add(double a,double b) { return a + b; }
double subtract(double a,double b) { return a - b; }```
This is my output:

usage : lab5c.exe <x>,<n>
where <x> = angle for sin estimate, in degrees
<n> = number of terms, a positive integer

3. The program requires you to input command-line parameters for it to do anything. If you're running from an IDE there are typically menu options you can work through to "set" these when running the program. Either that or the values you did provide could not be converted properly. How are you running the program (from an IDE or the command-line) and what options are you providing to the program?

4. Originally Posted by hk_mp5kpdw
The program requires you to input command-line parameters for it to do anything. If you're running from an IDE there are typically menu options you can work through to "set" these when running the program. Either that or the values you did provide could not be converted properly. How are you running the program (from an IDE or the command-line) and what options are you providing to the program?
I'm running the program through command-line. But the command prompt window closes immediately when I run through Dev C++ Compiler.

5. Originally Posted by alokrsx
the command prompt window closes immediately when I run through Dev C++ Compiler.
That's because you have the return -1 statement. It causes the program to immediately exit which closes the nice window the IDE opened for you. You'd need to put some type of blocking read op in there before the return statement to keep the window open instead of immediately closing.

Code:
```   if ((argc < 3) ||
(sscanf(argv[1],"%lg",&x) != 1) ||
(sscanf(argv[2],"%u",&n) != 1)) {
printf("usage : %s <x>,<n>\n",argv[0]);
printf(" where <x> = angle for sin estimate, in degrees\n");
printf(" <n> = number of terms, a positive integer\n");
return -1;
}```
Originally Posted by alokrsx
I'm running the program through command-line.
So what parameters are you passing to it?