Hi ,
I've written following program that takes a four digits integer from user and shows the digits on the screen separately i.e. if user enters 7531, it displays 7,5,3,1 .Any one can tell me how it can be written better and how to display digit in linear order i.e. if user enters 7531, it displays 1,3,5,7 .Thanks
#include <iostream>
using namespace std ;
main()
{
// declare variables
int number, digit;
// prompt the user for input
cout << "Please enter 4-digit number:";
cin >> number;
// get the first digit and display it on scree
digit = number % 10;
cout << "The digits are: " << digit << " , ";
// get the remaining three digits number
number = number / 10;
// get the next digit
digit = number % 10;
cout << digit << " , " ;
// get the next digit
number = number /10 ;
digit = number % 10 ;
cout <<digit << " , " ;
// get the remaining digit
number = number /10 ;
digit = number % 10 ;
cout <<digit << " , " ;
}