Skip to content

Instantly share code, notes, and snippets.

@juanfal
juanfal / intercambioOk.cpp
Created Oct 6, 2012
intercambio correcto con paso de parámetros por referencia
View intercambioOk.cpp
// nointercambio.cpp
// juanfc 2012-06-24
//
#include <iostream>
using namespace std;
void intercambio(int& a, int& b)
{
int temp = a;
@juanfal
juanfal / 03-12.forloopsum.cpp
Created Oct 10, 2012
for-loop sample. Summing up numbers
View 03-12.forloopsum.cpp
// 03-12.forloopsum.cpp
#include <iostream>
using namespace std;
const int TOP = 1000;
int main()
{
int sum = 0;
@juanfal
juanfal / 11.sumuntil0.cpp
Created Oct 10, 2012
enter numbers until 0. Sum them all
View 11.sumuntil0.cpp
// 11.sumuntil0.cpp
// juanfc 2011-10-21
// Ask for numbers until 0 is entered
// sum all the entered numbers
#include <iostream>
using namespace std;
int main()
{
@juanfal
juanfal / 15.histogram.cpp
Created Oct 10, 2012
simple histogram made with a for loop
View 15.histogram.cpp
// 15.histogram.cpp
// juanfc 2009-10-30
// ask for numbers until 0, making a simple histogram with them
// It looks better if you enter all the numbers in a row. Ex:
// 1 2 4 5 6 4 3 2 7 8 9 10 0
#include <iostream>
using namespace std;
int main()
@juanfal
juanfal / 02.esprimo_simple.cpp
Created Oct 11, 2012
simplest way of computing primality. Know if a number is prime. Slowest way
View 02.esprimo_simple.cpp
// 02.esprimo_simple.cpp
// juanfc 2009-10-16
#include <iostream>
using namespace std;
int main()
{
cout << "Please enter an integer: ";
int n;
cin >> n;
@juanfal
juanfal / functioncalls.cpp
Created Oct 12, 2012
funny example of a chain of calls to subprograms
View functioncalls.cpp
// functioncalls.cpp
// juanfc 2012-06-24
// funny example of a chain of calls to subprograms
#include <iostream>
using namespace std;
// Prototypes
void a();
void b();
@juanfal
juanfal / ecu2gradofun.cpp
Created Oct 16, 2012
ecuación de segundo grado con función
View ecu2gradofun.cpp
// ecu2gradofun.cpp
// juanfc 2009-11-07
//
#include <iostream>
#include <cmath>
using namespace std;
enum TIPOEC {CUALX, ABSURDA, PRIMERG, DOBLE, IMAG, DOSSOLS};
@juanfal
juanfal / ec2gradoPlana.cpp
Created Oct 16, 2012
Solución de la ecuación de segundo grado mediante if-elseifs planos, no anidados unos dentro de otros. Parece más fácil que anidando, ¿no? ¿Puedes poner esta solución dentro de una función?
View ec2gradoPlana.cpp
// ec2gradoPlana.cpp
// juanfc 2010-10-20
//
// Resuelve ecuaciones del tipo ax2 + bx + c=0
#include <iostream>
#include <cmath>
using namespace std;
@juanfal
juanfal / 02.Balance.cpp
Created Oct 17, 2012
How long does it take (in months) to accumulate a debt of €100 starting with a debt of €50 and being charged with 2% each months?
View 02.Balance.cpp
// 02.Balance.cpp
// from Savitch
// How long does it take (in months) to accumulate a debt
// of €100 starting with a debt of €50 and being charged with
// 2% each months?
#include <iostream>
using namespace std;
// consts
const float STARTING_DEBT = 50.0;
@juanfal
juanfal / 03.fact.cpp
Created Oct 17, 2012
How long can an integer be: for loop to compute a factorial
View 03.fact.cpp
// 03.fact.cpp
// juanfc 2003-11-11
// How long can an integer be:
// for loop to compute a factorial
#include <iostream>
using namespace std;
int main()
{