#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <locale>
struct pole
{
union // Данное обьединение позволяет определить остатки на 2 и 4
{
struct //Остаток от деления на 2
{
unsigned i1:1;
int:1;
} st1;
struct //Остаток от деления на 4
{
unsigned i1:2;
}st2;
} un;
int:14;
};
int main(int) // вычисление остатка от деления на 2 , 4
{
setlocale(LC_ALL,"rus");
printf("Введите число\n");
pole *pl;
int k;
scanf("%d",&k);
if(k<0) k*=-1; //Делаем из отрицательного числа положительное
pl=(pole *)&k;
printf("\n Остаток от деления на 2 =%d",pl->un.st1.i1);
printf("\n Остаток от деления на 4 =%d",pl->un.st2.i1);
getch();
}
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <locale>
struct pole
{
unsigned i1:1;
unsigned i2:1;
unsigned i3:1;
unsigned i4:1;
unsigned i5:1;
unsigned i6:1;
unsigned i7:1;
unsigned i8:1;
};
int main(int)
{
setlocale(LC_ALL,"rus");
printf("Алфавит в бинарном представлении\n");
pole *pl;
for(char sim='a';sim<='z';sim++)
{
printf("%c ",sim);
pl=(pole *)∼
printf(" %d",pl->i8);
printf(" %d",pl->i7);
printf(" %d",pl->i6);
printf(" %d",pl->i5);
printf(" %d",pl->i4);
printf(" %d",pl->i3);
printf(" %d",pl->i2);
printf(" %d",pl->i1);
printf("\n");
printf("\n");
}
getch();
}