fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. long a = 42556;
  7. long num;
  8. num=floor(log10(a))+1;
  9. //cout<<num<<" "<<"\n"; //this will print the number of digits in the number
  10.  
  11. cout<<"first num: "<<a/(int)pow(10,num-1)<<"\n";
  12. cout<<"last num: "<<a%10<<"\n";
  13. return 0;
  14. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
first num: 4
last num: 6