Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include<malloc.h>
  6.  
  7.  
  8. int GetCorrrectInt(int Min, int Max) {
  9. int Number = 1;
  10. bool isNotCorrect = false;
  11. do {
  12. scanf_s("%d", &Number);
  13. isNotCorrect = (Number < Max) && (Number > Min);
  14. if (isNotCorrect = false)
  15. do
  16. {
  17. printf("Variable must be in range [ ");
  18. printf_s("%d", Min);
  19. printf(",");
  20. printf_s("%d", Max);
  21. printf("]");
  22. } while (isNotCorrect);
  23. } while (isNotCorrect);
  24. return Number;
  25. }
  26.  
  27. void ArrOut( double* array, int size) {
  28. for (int i = size- 1; i >= 0; i--) {
  29. if (i != size - 1) {
  30. printf(", ");
  31. }
  32. printf("%6.3f", array[i]);
  33. }
  34. }
  35.  
  36. static int Division(int Num) {
  37. int i = 1;
  38. do {
  39. Num = Num / 10;
  40. i++;
  41. } while (Num / 10 != 0);
  42. return i;
  43. }
  44.  
  45. static bool BitComparison(int Num1, int Num2) {
  46. if (Division(Num1) != Division(Num2)) {
  47. printf("Digit capacity is not equal, try again");
  48. return false;
  49. }
  50. return true;
  51. }
  52.  
  53. void ArraySplit(double* Arr, int Num, int size) {
  54. for (int i = 0; i < size; i++) {
  55. Arr[i] = Num % 10;
  56. Num = Num / 10;
  57. }
  58. }
  59.  
  60. void main() {
  61. const int Min = 100;
  62. const int Max = 9999999;
  63. int FirstNum = 0;
  64. int SecondNum = 0;
  65. printf("Enter 2 numbers between 100 and 9999999\n");
  66. do {
  67. printf("Enter the first number\n");
  68. FirstNum = GetCorrrectInt(Min, Max);
  69. printf("Enter the second number\n");
  70. SecondNum = GetCorrrectInt(Min, Max);
  71. } while (!BitComparison(FirstNum, SecondNum));
  72. int arrSize = Division(FirstNum);
  73. double* ArrOf1 = malloc(sizeof(double) * arrSize);
  74. double* ArrOf2 = malloc(sizeof(double) * arrSize);
  75. double* ArrOf3 = malloc(sizeof(double) * arrSize);
  76. ArraySplit(ArrOf1, FirstNum, arrSize);
  77. ArraySplit(ArrOf2, SecondNum, arrSize);
  78. for (int i = 0; i < arrSize; i++) {
  79. ArrOf3[i] = ArrOf1[i] / ArrOf2[i];
  80. }
  81. ArrOut(ArrOf3, arrSize);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement