Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. unsigned fact( unsigned n )
  5. {
  6.     return ( n == 0 || n == 1 ) ? 1 : n * fact( n - 1 );
  7. }
  8.  
  9. int main()
  10. {
  11.  
  12.     double arr[] = { 0.0, 10.0, 3.0, 7.8,13.4 };
  13.     size_t n = sizeof(arr) / sizeof(arr[0]);
  14.  
  15.     double result;
  16.     bool has_result = false;
  17.  
  18.     for( unsigned i = 0; i < n; ++i )
  19.     {
  20.         if( (i+1) < arr[i] && arr[i] < fact(i) )
  21.         {
  22.             if( has_result ) result *= arr[i];
  23.             else
  24.             {
  25.                 has_result = true;
  26.                 result = arr[i];
  27.             }
  28.         }
  29.     }
  30.  
  31.     if( has_result )
  32.     {
  33.         result = 1 / result;
  34.         std::cout << "Result: " << result << std::endl;
  35.     }
  36.     else
  37.     {
  38.         std::cout << "Result does not exist!\n";
  39.     }
  40.  
  41.     _getch();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement