Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int cate_cifre(int n);
- void AfisareCifre(int n, int cifre);
- int main() {
- int n, cateCifre;
- cout << "N="; cin >>n;
- cateCifre = cate_cifre(n);
- switch(cateCifre) {
- case 1: {
- cout << n << endl;;
- break;
- }
- case 2: {
- cout << "- Cifra unitatilor: " << n % 10 << endl;
- n /= 10;
- cout << "- Cifra zecilor: " << n << endl;
- break;
- }
- case 3: {
- cout << "- Cifra unitatilor: " << n % 10 << endl;
- cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
- cout << "- Cifra sutelor: " << n / 100 << endl;
- break;
- }
- case 4: {
- cout << "- Cifra unitatilor: " << n % 10 << endl;
- cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
- cout << "- Cifra sutelor: " << (n / 100) % 10 << endl;
- cout << "- Cifra miilor: " << n / 1000 << endl;
- break;
- }
- case 5: {
- cout << "- Cifra unitatilor: " << n % 10 << endl;
- cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
- cout << "- Cifra sutelor: " << (n / 100) % 10 << endl;
- cout << "- Cifra miilor - unitati: " << (n / 1000) % 10 << endl;
- cout << "- Cifra miilor - zeci: " << n / 10000 << endl;
- break;
- }
- case 6: {
- cout << "- Cifra unitatilor: " << n % 10 << endl;
- cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
- cout << "- Cifra sutelor: " << (n / 100) % 10 << endl;
- cout << "- Cifra miilor - unitati: " << (n / 1000) % 10 << endl;
- cout << "- Cifra miilor - zeci: " << (n / 10000) % 10 << endl;
- cout << "- Cifra miilor - sutelor: " << n / 100000 << endl;
- break;
- }
- default: AfisareCifre(n, cateCifre);
- }
- return 0;
- }
- int cate_cifre(int n) {
- int nr_cifre = 0, c;
- while(n != 0) {
- c = n % 10;
- n /= 10;
- nr_cifre++;
- }
- return nr_cifre;
- }
- void AfisareCifre(int n, int cifre) {
- int v[101], i = 0, c;
- while(n != 0) {
- c = n % 10;
- n /= 10;
- v[i] = c;
- i++;
- }
- for(int j = 0; j < cifre; j++)
- cout << v[j] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement