Created
April 3, 2018 18:18
-
-
Save vitek999/dbf9ffa485a750b57ec27742d539c7a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// labaMiha3.cpp: определяет точку входа для консольного приложения. | |
// | |
#include "stdafx.h" | |
#include "testing.h" | |
#include "math.h" | |
#define MAX_ARRAY_SIZE 128 | |
int main() | |
{ | |
int array[MAX_ARRAY_SIZE]; | |
int realArrayLength; | |
int decNumbersCount = 1; | |
int decNumber = 0; | |
scanf("%d", &realArrayLength); | |
if (realArrayLength > 128 || realArrayLength < 1 || realArrayLength % 8 != 0) { | |
error_printf("invalid input data"); | |
return 0; | |
} | |
for (int i = 0; i < realArrayLength; ++i) { | |
scanf("%d", &array[i]); | |
if (array[i] != 1 && array[i] != 0) { | |
error_printf("invalid input data"); | |
return 0; | |
} | |
} | |
for (int i = 1; i <= realArrayLength; ++i) { | |
decNumber += array[i-1]*pow(2, decNumbersCount * 8-i); | |
if (i % 8 == 0) { | |
array[decNumbersCount-1] = decNumber; | |
++decNumbersCount; | |
decNumber = 0; | |
} | |
} | |
for (int i = 0; i < decNumbersCount - 1; ++i) { | |
printf("%d ", array[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment