Advertisement
pablopalacios

Funções legais

Oct 6th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double sum_pi(int n) {
  7.   return (pow((-1),n))/((2*n)+1);
  8. }
  9.  
  10. double pinto(int tamanho){
  11.   double r = 0;
  12.   for (int c=0; c<=tamanho; c++){
  13.     r += sum_pi(c);
  14.     }
  15.   return(4*r);
  16. }
  17.  
  18. double factorial(int n) {
  19.   double result = 1.0;
  20.   for (int c; c <= n; c++) {
  21.     result *= c;
  22.   }
  23.   return result;
  24. }
  25.  
  26. double sum_e(int x, int n){
  27.   double result = (pow(x,n))/factorial(n);
  28.   return result;
  29. }
  30.  
  31. void e(int x){
  32.   cout << exp(x) << endl;
  33.   double result = 0;
  34.   for (int c = 1; c <= 100; c++){
  35.     result += sum_e(x,c);
  36.     cout << result << " | ";
  37.     if (!(c % 10)){
  38.         cout << endl;
  39.     }
  40.   }
  41. }
  42.  
  43. int main(){
  44.   while(true){
  45.     cout << "Type qualquer porra: ";
  46.     long int tamanho;
  47.     cin >> tamanho;
  48.     e(tamanho);
  49.   }
  50.   return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement