forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsBinaryPalindrome.c
62 lines (59 loc) · 1.1 KB
/
IsBinaryPalindrome.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
/*
Check palindrome of Binary Numbers
*/
#include<stdio.h>
#include<string.h>
#include <stdbool.h>
char* getBinary(int x)
{
char ary[64];
int i=0;
while(x>0)
{
ary[i++]=x%2;
x/=2;
}
return ary;
}
bool isPalindrome(char ary[])
{
int len=strlen(ary);
printf("\n%d\n", len);
return false;
}
int main()
{
int x=0;
int choice=1;
char *array;
printf("Choice:\n1.Get N\n2.Generate Binary Equivalent\n3.Check Palindrome\n4.Exit \nEnter choice: ");
scanf("%d",&choice);
while(choice!=4)
{
switch (choice) {
case 1:
printf("Enter N:" );
scanf("%d",&x);
break;
case 2:
printf("\nGenerating Binary");
array=getBinary(x);
break;
case 3:
if(isPalindrome(array))
{
printf("\n%d is a binary palindrome!",x);
}
else
{
printf("\n%d is not a binary palindrome!",x);
}
break;
case 4:
break;
}
printf("Choice:\n1.Get N\n2.Generate Binary Equivalent\n3.Check Palindrome\n4.Exit \nEnter choice: ");
scanf("%d",&choice);
}
return 0;
}