Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Created January 10, 2011 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaDogg/772747 to your computer and use it in GitHub Desktop.
Save JaDogg/772747 to your computer and use it in GitHub Desktop.
Input 5 digit number and output it space separated
#include <iostream>
// #define WINDOWS_OS //enable this line if you are using windows
#define INP cout << "Input : ";
using namespace std;
int x10(int x) {
// this func calculate 10 to ther power x
int n,m ;
m = 1;
if (x>0){
for (n = 1; n <= x; n++) {
m *= 10;
};
}
return m;
}
int main()
{
int num,n1,n2,n3,n4,n5;
cout << "Type a five digit number" << endl
<< "Ex : 12345" << endl << endl;
INP
cin >> num;
while ((num < 9999) || (num > 99999))
{
#ifdef WINDOWS_OS
//windows cls
system("cls");
#else
// linux clear
system("clear");
#endif
cout << "Invalid Number" << endl;
INP
cin >> num;
}
n1 = num / x10(4);
n2 = (num % x10(4)) / x10(3);
n3 = (num % x10(3)) / x10(2);
n4 = (num % x10(2)) / x10(1);
n5 = (num % x10(1)) / x10(0);
cout << endl << n1 << " " << n2 << " " << n3 << " " << n4 << " " << n5;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment