Skip to content

Instantly share code, notes, and snippets.

@drifterz28
Created March 30, 2015 17:36
Show Gist options
  • Save drifterz28/97ec4d50773015bf14ce to your computer and use it in GitHub Desktop.
Save drifterz28/97ec4d50773015bf14ce to your computer and use it in GitHub Desktop.
spliting numbers in c++
// Example program
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// declaring variables:
int a, remainder;
int result, result2, result3;
// process:
a = 357;
result = floor(a / 100);
remainder = a % 100;
result2 = floor(remainder / 10);
remainder = a % 10;
result3 = remainder % 10;
// print out the result:
cout << result;
cout << result2;
cout << result3;
// terminate the program:
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment