Skip to content

Instantly share code, notes, and snippets.

View chbtoys's full-sized avatar

Carl H. Blomqvist chbtoys

View GitHub Profile
@chbtoys
chbtoys / 01-main.cpp
Created June 29, 2021 18:50
Code examples. From Paper to Code.
// From Paper to Code
// Square Root
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: \sqrt{16}
// LaTeX: \sqrt[3]{27}
// Test LaTeX: https://quicklatex.com/
#include <iostream>
#include <cmath>
int main() {
@chbtoys
chbtoys / 02-main.cpp
Created June 29, 2021 18:55
Code examples. From Paper to Code
// From Paper to Code
// Complex Numbers
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: 7 + 3i
// Test LaTeX: https://quicklatex.com/
#include <iostream>
#include <complex>
int main() {
// defines the complex number: (7.0 + 3.0i)
@chbtoys
chbtoys / 03-main.cpp
Created June 29, 2021 18:57
Code Examples. From Paper to Code.
// From Paper to Code
// Dot and Cross - vector multiplication
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: 3k \circ j
// Test LaTeX: https://quicklatex.com/
#include <iostream>
#include <vector>
void multiply(std::vector<int> &a, std::vector<int> &b, std::vector<int> &c)
{
@chbtoys
chbtoys / 04-main.cpp
Created June 29, 2021 18:58
Code Examples. From Paper to Code.
// From Paper to Code
// Dot and Cross - Dot Product
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: k\cdot j
// Test LaTeX: https://quicklatex.com/
#include <iostream>
#include <vector>
double dot(std::vector<double> &a, std::vector<double> &b)
{
@chbtoys
chbtoys / 05-main.cpp
Created June 29, 2021 18:59
Code Examples. From Paper to Code.
// From Paper to Code
// Dot and Cross - Cross Product
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: k \times j
// Test LaTeX: https://quicklatex.com/
#include <iostream>
#include <tuple>
std::tuple<double,double,double> cross(std::tuple<double,double,double> &a, std::tuple<double,double,double> &b)
{
@chbtoys
chbtoys / 06-main.cpp
Created June 29, 2021 19:01
Code Examples. From Paper to Code.
// From Paper to Code
// Sigma - Summation
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: \sum_{i=1}^{100} i
// Test LaTeX: https://quicklatex.com/
#include <iostream>
int main() {
int sum=0;
for (int i=1;i<=100;i++)
@chbtoys
chbtoys / 07-main.cpp
Created June 29, 2021 19:01
Code Examples. From Paper to Code.
// From Paper to Code
// Sigma - Summation
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: \sum_{i=1}^{100} (2i + 1)
// Test LaTeX: https://quicklatex.com/
#include <iostream>
int main() {
int sum=0;
for (int i=1;i<=100;i++)
@chbtoys
chbtoys / 08-main.cpp
Created June 29, 2021 19:04
Code Examples. From Paper to Code.
// From Paper to Code
// Sigma - Summation
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: \sum_{i=1}^{2} \sum_{j=4}^{6} (3ij)
// Test LaTeX: https://quicklatex.com/
#include <iostream>
int main() {
int sum=0;
for (int i = 1; i <= 2; i++) {
@chbtoys
chbtoys / 09-main.cpp
Created June 29, 2021 19:05
Code Examples. From Paper to Code.
// From Paper to Code
// Capital Pi - Product
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: \prod_{i=1}^{6} i
// Test LaTeX: https://quicklatex.com/
#include <iostream>
int main() {
int prod = 1;
for (int i = 1; i <= 6; i++) {
@chbtoys
chbtoys / 10-main.cpp
Created June 29, 2021 19:06
Code Examples. From Paper to Code.
// From Paper to Code
// Pipes - Absolute Value
// Run with: https://www.jdoodle.com/online-compiler-c++17/
// LaTeX: |x|
// Test LaTeX: https://quicklatex.com/
#include <iostream>
int main() {
int x = -5;
int result = std::abs(x);