Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- unsigned fact( unsigned n )
- {
- return ( n == 0 || n == 1 ) ? 1 : n * fact( n - 1 );
- }
- int main()
- {
- double arr[] = { 0.0, 10.0, 3.0, 7.8,13.4 };
- size_t n = sizeof(arr) / sizeof(arr[0]);
- double result;
- bool has_result = false;
- for( unsigned i = 0; i < n; ++i )
- {
- if( (i+1) < arr[i] && arr[i] < fact(i) )
- {
- if( has_result ) result *= arr[i];
- else
- {
- has_result = true;
- result = arr[i];
- }
- }
- }
- if( has_result )
- {
- result = 1 / result;
- std::cout << "Result: " << result << std::endl;
- }
- else
- {
- std::cout << "Result does not exist!\n";
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement