Write C++ program to find first and last digit of any number


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int num, last;
  9.  
  10. //Reading a number from user
  11. cout<<"Enter any number:";
  12. cin>>num;
  13.  
  14. last = num%10;
  15.  
  16. cout<<"The last digit of entered number: "<< last<<endl;
  17.  
  18. while(num>=10)
  19. {
  20. num = num/10;
  21. }
  22.  
  23. cout<<"The first digit of entered number: "<<num;
  24.  
  25. return 0;
  26. }

Result

C++ language techstudy.org

     





Related Topics




Popular Posts