miércoles, 18 de mayo de 2016

Fibonacci C++

Fibonacci  C++

#include <iostream>
using namespace std;

long fibonacci (long);

int main(){
long result;
int i;
for (i=0; i<=10; i++)
result = fibonacci(i);
cout << i << endl;

system ("pause";
return 0;
}

long fibonacci(long i){

if(i == 0 || i == 1) //caso base
return i;

else
return fibonacci(i-1)+fibonacci(i-2);
}

Numero factorial C++

Numero factorial C++

#include <iostream.h>
using namespace std;
unsigned int factorial(int);
int permutacion(int);
int combinacion(int);
int main(){
int x,y;
cin>>x;
y=factorial(x);
cout<<"n El factorial de "<<x<<" es: "<<y;


return 0;

}
unsigned int factorial(int n){

if(n==0||n==1)
return 1;
return n*factorial(n-1);
}

int permutacion(int n, int r){
return factorial(n)/factorial(n-1);
}

int combinacion(int n, int r){
return factorial(n)/(factorial(n-1)*factorial(r));
}

numeros primos C++

numeros primos C++


#include<iostream>
using namespace std;

int main(){

unsigned int numero, n, p, num_columnas;
cout <<"Introduzca hasta que numero quiere llegar ";
cin >> numero;
cout <<'n' << endl;
num_columnas = 0 ;
n=2;
while (n <= numero){
for ( p = 2; n % p!= 0; p++);
if ( p == n){
cout << n <<", ";
if(++num_columnas % 10 == 0)// controla el numero de elementos en una fila
cout <<"n" << endl;
}
n++;
}

cout <<"Fin de Programa. n" << endl;
system ("pause";
return 0;
}

ENTRADAS POPULARES