Adding python files

This commit is contained in:
Arkagedon
2022-03-13 19:40:00 +01:00
parent 96c71d1d71
commit 70f29fa19e
22 changed files with 320 additions and 32 deletions

48
C/Easy_Challenges/unary.c Executable file
View File

@ -0,0 +1,48 @@
#include <stdio.h>
//Convert char into binary ascii
void charToBin(char c, char *buffer)
{
for (int i = 6; i >=0; i--)
{
buffer[i] = '0' + c%2;
c/=2;
}
buffer[7] = '\n';
}
int main()
{
char MESSAGE[101], binary[8], binMessage[707], prev;
int i = 0, j = 0, count = 0;
scanf("%[^\n]", MESSAGE);
binMessage[0] = '\0'; //Reset the string
for (int i = 0; i < strlen(MESSAGE); i++)
{
charToBin(MESSAGE[i], binary);
strncat(binMessage,binary,7); //Adding the binary of each char into the binMessage string
}
for (i =0; binMessage[i] != '\0'; i++)
{
if (binMessage[i] != prev)
{
for (j=0; j<count; j++)
printf("0");
if (count != 0)
printf(" ");
printf((binMessage[i] == '0') ? "00 " : "0 ");
count =1;
}
else
count++;
prev = binMessage[i];
}
for (int j = 0 ; j < count ; j++) //Showing the rest of the binMessage string
printf("0");
return 0;
}