Created
January 10, 2011 13:02
-
-
Save JaDogg/772747 to your computer and use it in GitHub Desktop.
Input 5 digit number and output it space separated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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