Skip to content

Instantly share code, notes, and snippets.

@sr229
Created August 18, 2019 00:49
Show Gist options
  • Save sr229/f9ff48870529da1f98857539545e2e9d to your computer and use it in GitHub Desktop.
Save sr229/f9ff48870529da1f98857539545e2e9d to your computer and use it in GitHub Desktop.
CS-111 files
/**
* Copyright 2019 (c) Ralph Wilson Aguilar
* For CS-111
* Do not copy or redistribute without permission.
*/
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int exponent, result;
cout << "Choose the exponent for 2: ";
cin >> exponent;
// we use pow() from cmath to do the heavy lifting for us
// it basically multiplies 2 to itself to N times (exponent).
result = pow(2.0 , exponent);
cout << "2 to the power of " << exponent << " is " << result << endl;
}
/**
* Copyright 2019 (c) Ralph Wilson Aguilar
* For CS-111
* Do not copy or redistribute without permission.
*/
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int exponent, result;
cout << "Enter the exponent for e: ";
cin >> exponent;
// I'm really sure this is natural log. If not, the instructor can make me do a 10 second squat
// According to Google, e^x (natural log) is equal to 1 so idk about that.
result = log(exponent);
cout << "The natural logarithm of " << exponent << " is " << result << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment