Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int mcd(int a, int b)
- {
- if(b==0){
- return a;
- }
- else{
- return mcd(b,a%b);
- }
- }
- int fibonacci(int a){
- if(a == 0){
- return 0;
- }
- if(a == 1){
- return 1;
- }
- return fibonacci(a-1) + fibonacci(a-2);
- }
- bool numeroexacto(int n){
- int s,i;
- s=0;
- for (i=1;i<n-1;i++){
- if (n % i == 0){
- s +=i;
- }
- }
- if (n == s){
- return true;
- }
- else{
- return false;
- }
- }
- bool par(int a){
- return a%2 == 0;
- }
- int main(){
- //FIBONACCI
- int a;
- cout<<"Suministre el numero a calcular fibonacci, primo, par y numero exacto:"<<endl;
- cin>>a;
- cout<<endl;
- int fib = fibonacci(a);
- //PRIMO
- bool p = true;
- for (int i=2; i<a; i++){
- if(mcd(a,i)!=1){
- p = false;
- }
- }
- //NUMERO EXACTO
- bool esexacto = numeroexacto(a);
- //PAR
- if(par(a)){
- cout<<"Es par"<<endl;
- }
- else{
- cout<<"Es impar"<<endl;
- }
- //IMPRIMIR RESULTADOS
- cout<<"Fibonacci: "<<fib<<endl;
- if(p){
- cout<<"Si es primo"<<endl;
- }
- else{
- cout<<"No es primo"<<endl;
- }
- if(esexacto){
- cout<<"Es un numero exacto"<<endl;
- }
- else{
- cout<<"No es un numero exacto"<<endl;
- }
- //FINALIZA EL PROGRAMA
- fflush(stdin);
- getchar();
- return 0;
- }
- //By RecatoDK for YahooRespuestas!
Add Comment
Please, Sign In to add comment