Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <math.h>
- #include <stdlib.h>
- #include<malloc.h>
- int GetCorrrectInt(int Min, int Max) {
- int Number = 1;
- bool isNotCorrect = false;
- do {
- scanf_s("%d", &Number);
- isNotCorrect = (Number < Max) && (Number > Min);
- if (isNotCorrect = false)
- do
- {
- printf("Variable must be in range [ ");
- printf_s("%d", Min);
- printf(",");
- printf_s("%d", Max);
- printf("]");
- } while (isNotCorrect);
- } while (isNotCorrect);
- return Number;
- }
- void ArrOut( double* array, int size) {
- for (int i = size- 1; i >= 0; i--) {
- if (i != size - 1) {
- printf(", ");
- }
- printf("%6.3f", array[i]);
- }
- }
- static int Division(int Num) {
- int i = 1;
- do {
- Num = Num / 10;
- i++;
- } while (Num / 10 != 0);
- return i;
- }
- static bool BitComparison(int Num1, int Num2) {
- if (Division(Num1) != Division(Num2)) {
- printf("Digit capacity is not equal, try again");
- return false;
- }
- return true;
- }
- void ArraySplit(double* Arr, int Num, int size) {
- for (int i = 0; i < size; i++) {
- Arr[i] = Num % 10;
- Num = Num / 10;
- }
- }
- void main() {
- const int Min = 100;
- const int Max = 9999999;
- int FirstNum = 0;
- int SecondNum = 0;
- printf("Enter 2 numbers between 100 and 9999999\n");
- do {
- printf("Enter the first number\n");
- FirstNum = GetCorrrectInt(Min, Max);
- printf("Enter the second number\n");
- SecondNum = GetCorrrectInt(Min, Max);
- } while (!BitComparison(FirstNum, SecondNum));
- int arrSize = Division(FirstNum);
- double* ArrOf1 = malloc(sizeof(double) * arrSize);
- double* ArrOf2 = malloc(sizeof(double) * arrSize);
- double* ArrOf3 = malloc(sizeof(double) * arrSize);
- ArraySplit(ArrOf1, FirstNum, arrSize);
- ArraySplit(ArrOf2, SecondNum, arrSize);
- for (int i = 0; i < arrSize; i++) {
- ArrOf3[i] = ArrOf1[i] / ArrOf2[i];
- }
- ArrOut(ArrOf3, arrSize);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement