fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4.  
  5. /* prototype declaration */
  6. long fact(int);
  7. double computeSine(double x, n);
  8.  
  9. /* Main Function */
  10. int main(int argc, char **argv) {
  11.  
  12. if(argc != 3) {
  13. fprintf(stderr, "Usage: %s x n\n", argv[0]);
  14. exit(1);
  15. }
  16.  
  17. double result = 0.0;
  18. double x = atof(argv[1]);
  19. n = atoi(argv[2]);
  20.  
  21. result = computeSine(x, n , 10);
  22. printf("sin(%lf) = %d\n", x, result);
  23. return 0;
  24. }
  25.  
  26.  
  27.  
  28. /* Factorial Function */
  29. long fact(int n) {
  30. long result = 1, i;
  31. for(i=2; i<=n; i++) {
  32. result *= i;
  33. }
  34. return result;
  35. }
  36.  
  37. /* compute sin(x) using a taylor series out to n terms */
  38. double computeSine(double x, int n){
  39.  
  40. double result = 0.0
  41. int i=0;
  42. for(i=0; i<n; i++){
  43. double term = pow(-1,i) * (pow(x, 2*i+1)/fcat(2*i+1));
  44. Result += term;
  45. }
  46. return ;
  47.  
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:7:31: error: unknown type name 'n'
 double computeSine(double x,  n);
                               ^
prog.c: In function 'main':
prog.c:19:3: error: 'n' undeclared (first use in this function)
   n = atoi(argv[2]);
   ^
prog.c:19:3: note: each undeclared identifier is reported only once for each function it appears in
prog.c:21:12: warning: implicit declaration of function 'computeSine' [-Wimplicit-function-declaration]
   result = computeSine(x, n , 10);
            ^
prog.c:22:10: warning: format '%d' expects argument of type 'int', but argument 3 has type 'double' [-Wformat=]
   printf("sin(%lf) = %d\n", x, result);
          ^
prog.c: At top level:
prog.c:38:8: error: conflicting types for 'computeSine'
 double computeSine(double x, int n){
        ^
prog.c:21:12: note: previous implicit declaration of 'computeSine' was here
   result = computeSine(x, n , 10);
            ^
prog.c: In function 'computeSine':
prog.c:41:3: error: expected ',' or ';' before 'int'
   int i=0;
   ^
prog.c:42:7: error: 'i' undeclared (first use in this function)
   for(i=0; i<n; i++){
       ^
prog.c:43:46: warning: implicit declaration of function 'fcat' [-Wimplicit-function-declaration]
     double term = pow(-1,i) * (pow(x, 2*i+1)/fcat(2*i+1));
                                              ^
prog.c:44:5: error: 'Result' undeclared (first use in this function)
     Result += term;
     ^
prog.c:46:3: warning: 'return' with no value, in function returning non-void
   return ;
   ^
prog.c:40:10: warning: unused variable 'result' [-Wunused-variable]
   double result = 0.0  
          ^
stdout
Standard output is empty