Skip to content

Instantly share code, notes, and snippets.

@juanfal
juanfal / konesinarow.cpp
Created November 22, 2012 08:50
Counting 1s in a binary number nested loops
// konesinarow.cpp
// juanfc 2012-06-24
// Design a program that reads from keyboard two natural numbers $k$ and
// $n$ and sends to the screen a message that indicates whether $n$ has
// got at least $k$ 1s (ones) straight without a break, or not. For example,
// if $k=3$ and $n=135$ the program should display ‘Yes’ since 135 as binary
// is ‘1000 0111’ that does have at least 3 ones in a row.
@juanfal
juanfal / stringtest.cpp
Created November 26, 2012 13:24
Intro to strings… tests
// stringtest.cpp
// juanfc 2009-02-25
// http://www.cplusplus.com/reference/string/string/
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
@juanfal
juanfal / structsample.cpp
Created November 26, 2012 13:47
Struct sample
// structsample.cpp
// juanfc 2011-12-08
//
#include <iostream>
using namespace std;
// types
enum TMonth { JAN, FEB, MAR, APR, MAY, JUN,
JUL, AUG, SEP, OCT, NOV, DEC };
@juanfal
juanfal / astros.cpp
Created November 26, 2012 14:36
Structs help astros modelling
// planetas.cpp
// juanfc 2012-06-24
//
#include <iostream>
#include <cmath>
using namespace std;
const float G = 6.6738410E-11; // N·m2/kg2
@juanfal
juanfal / isprimefunc.cpp
Created December 2, 2012 20:29
is prime?
bool isPrime(unsigned num)
{
int i = 2;
while (i < num and num % i != 0)
++i;
return i >= num;
}
@juanfal
juanfal / mesdeunafecha.cpp
Created December 4, 2012 13:11
Mes de una fecha en cadenas
// mesdeunafecha.cpp
// juanfc 2012-06-24
//
#include <iostream>
using namespace std;
string mesdeunafecha(string fecha);
@juanfal
juanfal / euler3.cpp
Created December 6, 2012 13:11
Solution to the 3rd EulerProj problem
// euler3.cpp
// juanfc 2012-06-24
// The prime factors of 13195 are 5, 7, 13 and 29.
// What is the largest prime factor of the number 600851475143 ?
#include <iostream>
using namespace std;
int main()
{
@juanfal
juanfal / base.cpp
Created December 6, 2012 20:54
Base change, recursive and with a default value to 10
#include <iostream>
using namespace std;
void binary (int a, int base = 10);
int main()
{
int a, base;
cout << "Enter number and base:";
cin >> a >> base;
@juanfal
juanfal / 004.palindromeLargest.cpp
Created December 6, 2012 22:24
Largest palindrome built with n digits
// 004.palindromeLargest.cpp
// juanfc 2012-06-24
// A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
// Find the largest palindrome made from the product of two 3-digit numbers.
#include <iostream>
using namespace std;
const int NOOFDIGITS = 3;
@juanfal
juanfal / 004.palindromeLargest.cpp
Created December 7, 2012 10:40
Largest palindrome using string
// 004.palindromeLargest.cpp
// juanfc 2012-06-24
// A palindromic number reads the same both ways. The largest palindrome made
// from the product of two 2-digit numbers is 9009 = 91 x 99.
// Find the largest palindrome made from the product of two 3-digit numbers.
#include <iostream>
#include <sstream>
using namespace std;