Translate

program to inputs a five-digit number, separates the number


Question:
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.)

Answer:


#include <iostream>

using namespace std;
int main()
 {
 int num;

 cout << "Enter a five-digit number: ";
 cin >> num;

 cout << num / 10000 << " ";
 num = num % 10000;
 cout << num / 1000 << " ";
 num = num % 1000;
 cout << num / 100 << " ";
 num = num % 100;
 cout << num / 10 << " ";
 num = num % 10;
 cout << num << endl;

 return 0;
  }

No comments:

Post a Comment