fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. int number;
  7. double x;
  8. cin>>x>>number;
  9. double value;
  10. double partial_amount=0;
  11. int n=1;
  12. while(n<=number){
  13. value=(cos((n*x))-cos(((n+1)*x)))/n;
  14. cout<<value<<" ";
  15. partial_amount+=value;
  16. n++;
  17. }
  18. cout<<endl;
  19. cout<<partial_amount;
  20. return 0;
  21. }
Success #stdin #stdout 0s 16064KB
stdin
100 4
stdout
0.375131 0.254642 0.167733 0.0896382 
0.887145