Skip to content

Instantly share code, notes, and snippets.

@juanfal
juanfal / intercambioOk.cpp
Created October 6, 2012 20:11
intercambio correcto con paso de parámetros por referencia
// 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 October 10, 2012 11:54
for-loop sample. Summing up numbers
// 03-12.forloopsum.cpp
#include <iostream>
using namespace std;
const int TOP = 1000;
int main()
{
int sum = 0;
@juanfal
juanfal / 11.sumuntil0.cpp
Created October 10, 2012 12:07
enter numbers until 0. Sum them all
// 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 October 10, 2012 12:18
simple histogram made with a for loop
// 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 October 11, 2012 06:38
simplest way of computing primality. Know if a number is prime. Slowest way
// 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 October 12, 2012 19:28
funny example of a chain of calls to subprograms
// 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 October 16, 2012 11:42
ecuación de segundo grado con función
// 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 October 16, 2012 23:08
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?
// 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 October 17, 2012 07:48
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?
// 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 October 17, 2012 12:12
How long can an integer be: for loop to compute a factorial
// 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()
{