Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath> // For pow()
- using namespace std;
- struct CV {
- int numbs[100];
- int count;
- };
- int pow2(int x, int y);
- int countNumber(int n);
- CV splitNumbers(int N);
- int main() {
- CV student = splitNumbers(12345678);
- for (int i = 0; i < student.count; i++) {
- cout << student.numbs[i] << endl;
- }
- return 0;
- }
- int countNumber(int n) {
- int count = 0;
- while (n > 0) {
- count++;
- n /= 10;
- }
- return count;
- }
- CV splitNumbers(int N) {
- CV result;
- int index = 0;
- result.count = countNumber(N);
- while (N > 0) {
- int divisor = pow2(10, result.count - 1);
- result.numbs[index++] = N / divisor;
- N %= divisor;
- result.count--;
- }
- result.count = index; // Update the count to actual numbers added
- return result;
- }
- int pow2(int x, int y) {
- int result = 1;
- for (int i = 0; i < y; i++) {
- result *= x;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement