code plz

write a program that inputs a five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each. (Hint: Use the integer division and modulus operators.) For example, if the user types in 42339 the program should print 4 2 3 3 9
I could write that using a string.. Although I'm certain that's not what your instructor's looking for in that assignment. Hah.
@Moschops thanks i got the answer from that link..

I was looking for the code in c++ but I converted it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Write a program that inputs a five-digit number, separates the number into its
// individual digits and prints the digits separated from one anotyher by three 
// spaces each. (Hint: Use the integer division and modulus operator.) (for expample,
// if the user types in 42339 the program should print
// 4   2   3   3   9

// answer

#include <iostream>
using namespace std;

int main()
{
	int a;
	
	cout << "Enter a five-digit number: ";
	cin >> a;
	
	cout << a / 10000 << "   ";
	a = a % 10000;
	
	cout << a / 1000 << "   ";
	a = a % 1000;
	
	cout << a / 100 << "   ";
	a = a % 100;
	
	cout << a / 10 << "   ";
	a = a % 10;
	
	cout << a / 1;
	
	return 0;
}
// compiled successfully with Orwell dev-cpp 
Last edited on
Topic archived. No new replies allowed.