This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rand; // rand crate for generating random numbers | |
use std::io; // io library from standard library | |
use std::io::Write; // Needed for flushing stdout after print. | |
use std::cmp::Ordering; // For comparing values | |
use rand::Rng; // from rand crate | |
fn main() { | |
println!("Guess the number, from 0 to 100."); // Greet user | |
let secret_number = rand::thread_rng().gen_range(0, 101); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Abdullah Khan | |
// Compile with: g++ -std=c++14 k-th_smallest_element.cpp | |
// Second smallest value in unsorted array/vector/list | |
#include <iostream> | |
#include <vector> | |
#include <utility> | |
#include <random> | |
using Generator = std::mt19937; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with g++ -std=c++14 reverse.cpp | |
#include <iostream> // std::cout | |
#include <string> // std::string | |
#include <utility> // std::swap | |
using namespace std; | |
string reverse(string & s) { | |
// Ternary conditional | |
// If string is of even length, n = string length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File: progress_bar_example.cpp | |
// Modified from https://stackoverflow.com/questions/14539867/how-to-display-a-progress-indicator-in-pure-c-c-cout-printf | |
// Compile with: | |
// g++ -std=c++14 -o prog progress_bar_example.cpp -Werror -pedantic | |
#include <iostream> | |
#include <chrono> // for literals | |
#include <thread> // for cross-platform sleep | |
int main() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author: Abdullah Khan | |
Purpose: Show off C++14 automatic return type deduction. | |
Build: g++ -std=c++14 automatic_return_type_deduction.cpp -o create_pair | |
Run: Invoke create_pair with two parameters: words or numbers work best. | |
*/ | |
#include <iostream> | |
#include <utility> |
NewerOlder