Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void fibonacci(int, long long int []);
- long long int factorial(const int);
- bool esPrimo(const int);
- int main()
- {
- int cant, tam=30;
- //Si el num solicitado es menor o igual que 1
- do{
- cout << "Cuántos números fibonacci quieres?"<<endl;
- cin>>cant;
- }while(cant<=1);
- long long int fibs[cant];
- fibonacci(cant, fibs);
- cout<<"\n\n";
- for(int i=cant-1; i>=0; i--)
- if( esPrimo(fibs[i]) )
- cout<<"El factorial de "<<fibs[i]<<" es "<<factorial(fibs[i])<<endl;
- return 0;
- }
- void fibonacci(const int elem, long long int arr[]){
- int fibo1, fibo2;
- fibo1=1;
- fibo2=1;
- arr[0]=fibo1;
- for(int i=2; i<=elem; i++){
- arr[i-1]=fibo2;
- fibo2 = fibo1 + fibo2;
- fibo1 = fibo2 - fibo1;
- }
- }
- long long int factorial(const int numero){
- long long int acum=1;
- int num=numero;
- (num<0)?(num*=-1):num;
- if( num==0 )
- return 1;
- for(int i=1; i<=num; i++)
- acum *= i;
- return acum;
- }
- bool esPrimo(const int num){
- if( num<0 )
- return 0;
- for(int i=2; i<=(num/2); i++)
- if( num%i==0 )
- return 0;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement