Skip to content

Instantly share code, notes, and snippets.

@LionZXY
Created September 26, 2017 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LionZXY/4f6934751744e851721249af4ed6d319 to your computer and use it in GitHub Desktop.
Save LionZXY/4f6934751744e851721249af4ed6d319 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <slcurses.h>
/**
* Задать массив
* n=0
* Ввести в массив значения
* Взять первое число
* Это буквы или цифры если буквы, то переход к следующему. - это не реализуемо. Как мы поймем что это буквы?
* Если цифры, то:
* Делить на 10
* Пока (остаток меньше 2-х и целое не равно нулю)
* а[i]=a[i]*(2^n)
* n=n+1
* b=a[i]
* c=b+a[i].
* Если целое равно 0, то вывести с
* @return
*/
void writeToBit(int *number, bool bit, int num) {
bool tmpval = 1;
int tmp = *number;
tmpval = (tmpval << num);//устанавливаем нужный бит в единицу
tmp = (tmp & (~tmpval));//сбрасываем в 0 нужный бит
if (bit) { // если бит требуется установить в 1
tmp = (tmp | (tmpval));//то устанавливаем нужный бит в 1
}
*number = tmp;
}
int main() {
int *array = 0; // Задать массив
int arrayCount = 0;
printf("Введите количество чисел:");
scanf("%d", &arrayCount); // Просим пользователя ввести количество элементов в массиве
array = malloc(sizeof(int) * arrayCount); // Создаем массив длинны N
// Твой код
// Старт
for (int i = 0; i < arrayCount; i++) {
printf("A[%d] = ", i);
if (scanf("%d", &array[i]) == 0) {
printf("Ввод неверный. Эта переменная будет равна 0");
array[i] = 0;
}
}
printf("\n");
// Конец
int n = 0;
for (int i = arrayCount - 1; i >= 0; i--) {
if (array[i] == 0 || array[i] == 1) {
writeToBit(&n, array[i], i);
}
}
printf("%d", n);
free(array); // Подчищаем за собой
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment