Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int inputData(int min, int max) {
- int n = 0;
- bool isIncorrect;;
- do {
- cin >> n;
- isIncorrect = false;
- if (cin.fail() || (n < min) || (n > max) ) {
- cout << "Please, enter a positive integer number:" << endl;
- isIncorrect = true;
- cin.clear();
- while (cin.get() != '\n');
- }
- } while (isIncorrect);
- return n;
- }
- int enterArraySize() {
- cout << "Input number of digits:" << endl;
- const int min = 1;
- const int max = 10;
- return inputData(min, max);
- }
- int* inputArray(int n) {
- const int min = 1;
- const int max = 9;
- int* arr;
- arr = new int[n];
- cout << "Enter the numbers one by one: " << endl;
- for (int i = 0; i < n; i++)
- arr[i] = inputData(min, max);
- return arr;
- }
- int arrayToInt(int n, int* arr) {
- int c = 0;
- for (int i = 0; i < n; i++)
- c = c * 10 + arr[i];
- return c;
- }
- void divide(float number1, float number2) { // вывод по цифрам
- float number = number1 / number2;
- int k = 1;
- int numberForLoopVirgin = int(number); // переменная для цикла1 while
- if (numberForLoopVirgin == 0)
- k = 0;
- else
- while ((numberForLoopVirgin /= 10) > 0) // количество знаков в целой части изначального числа
- k++;
- cout << "How many decimal places do you want to output? (<= 6)" << endl; // знаков после запятой
- int demicalPlaces = 0;
- const int min = 1;
- const int max = 7;
- demicalPlaces = inputData(min, max);
- for (int i = 0; i < demicalPlaces; i++)
- number = number * 10; // домножение на 10 "demicalPlaces" раз
- int n = demicalPlaces + k;
- int* arr;
- arr = new int[n];
- int numberInt = int(number); // float to int (уже домноженное число)
- for (int i = 0; i < n; i++) { // этот цикл создает массив из цифр числа. 1000 -> 1 0 0 0
- arr[i] = numberInt % 10;
- numberInt /= 10;
- }
- cout << "Result is: " << endl;
- if (k == 0)
- cout << "0" << endl;
- for (int i = n - 1; i > (demicalPlaces - 1); i--)
- cout << arr[i] << endl;
- if (demicalPlaces > 0) {
- cout << "," << endl;
- for (int i = demicalPlaces - 1; i > -1; i--)
- cout << arr[i] << endl;
- }
- }
- int main() {
- int size1 = enterArraySize();
- int* arr1 = inputArray(size1);
- float number1 = arrayToInt(size1, arr1);
- int size2 = enterArraySize();
- int* arr2 = inputArray(size2);
- float number2 = arrayToInt(size2, arr2);
- divide(number1, number2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement