-
Notifications
You must be signed in to change notification settings - Fork 0
/
algo.c
66 lines (64 loc) · 1.27 KB
/
algo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// main.c
// pract
//
// Created by SUVANSH ARORA on 16/02/21.
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
// insert code here..
char ch[16];
printf("enter a string : ");
scanf("%[^\n]s",ch);
printf("%s",ch);
int len=0;
int i=0;
while(ch[i]!='\0'){
len++;
i++;
}
int a,b;
i=0;
for( i=0;i<len;i+=2){
printf("\n");
printf("%c %c",ch[i],ch[i+1]);
a=(int)ch[i];
if(i+1!=len){
b=(int)ch[i+1];}
else
b=0;
int first[8]={0};
int second[8]={0};
int z=0;
while(a>0){
if(a%2==0)
first[7-z]=0;
else
first[7-z]=1;
a=a/2;
z++;
}
z=0;
while(b>0){
if(b%2==0)
second[7-z]=0;
else
second[7-z]=1;
b=b/2;
z++;
}
int msg[16];
for(int j=0;j<8;j++)
msg[j]=first[j];
for(int j=8;j<16;j++)
msg[j]=second[j-8];
printf("\n");
for(int j=0;j<16;j++)
printf("%d",msg[j]);
}
for(int i=0;i<len;i++)
printf("%c",ch[i]);
return 0;
}