COS SERIES Program in C

  1. #include<stdio.h>  
  2.   
  3. #include<conio.h>  
  4.   
  5. #include<math.h>  
  6.   
  7. main()  
  8.   
  9. {  
  10.   
  11. int i,n,x;  
  12.   
  13. float t,s;  
  14.   
  15. clrscr();  
  16.   
  17. printf("enter the value of k,n \n");  
  18.   
  19. scanf("%d%d",&x,&n);  
  20.   
  21. t=1;  
  22.   
  23. s=1;  
  24.   
  25. for(i=1;i<=n-1;i++)  
  26.   
  27. {  
  28.   
  29. t=(-1)*((pow(x,2)*t*i))/((2*i)*((2*i- 1)*i));  
  30.   
  31. s=s+t;  
  32.   
  33. printf("s=%6.2f & t=%6.2f\n",s,t);  
  34.   
  35. }  
  36.   
  37. printf("\n sum of the cos series=%5.2f\n",s);  
  38.   
  39. return(0);  
  40.   
  41. }