-
Notifications
You must be signed in to change notification settings - Fork 0
/
yourname.c
60 lines (57 loc) · 996 Bytes
/
yourname.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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
void decimaltobinary(int x);
int main(void)
{
char name[30];
int i, len;
system("cls");
printf("Enter your name to convert to ASCII and binary: ");
gets(name);
printf("Your name in ASCII: ");
for (i = 0, len = strlen(name); i < len; i++)
{
if (isspace(name[i]))
{
printf(" ");
}
else if (isalpha(name[i]))
{
printf("%d ", name[i]);
}
}
printf("\n");
printf("Your name in binary: ");
for (i = 0, len = strlen(name); i < len; i++)
{
if (isspace(name[i]))
{
printf(" ");
}
else if (isalpha(name[i]))
{
decimaltobinary((int)name[i]);
printf(" ");
}
}
printf("\n");
system("pause");
return 0;
}
void decimaltobinary(int x)
{
int i;
int rem[8];
int r;
for (i = 0; x > 0; i++)
{
rem[i] = x % 2;
x = x / 2;
}
for (i = i - 1; i >= 0; i--)
{
printf("%d", rem[i]);
}
}