Skip to content

Commit 0d0adad

Browse files
binary number using the concept of dynamic memoric allocation
1 parent 591f6cc commit 0d0adad

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<stdio.h>
2+
#include<conio.h>
3+
#include<math.h>
4+
5+
int checking(char*,int);
6+
void main()
7+
{
8+
int b,i;
9+
char *a;
10+
a=(char*)calloc(b,sizeof(char));
11+
printf("\nhow many digit binary you want to enter\n");
12+
scanf("%d",&b);
13+
14+
printf("\nenter the binary number");
15+
fflush(stdin);
16+
gets(&a[0]);
17+
if(checking(a,b))
18+
{
19+
printf("\nthe given binary number after converting into decimal is a multiple of 3");
20+
}
21+
else
22+
printf("\nthe given binary number after converting into decimal is not a multiple of 3");
23+
getch();
24+
free(a);
25+
}
26+
int checking(char *a,int b)
27+
{
28+
int i,j=0,sum=0;
29+
30+
for(i=b-1;i>=0;i--)
31+
{
32+
sum=sum+pow(2,j)*(int)*(a+i);
33+
j++;
34+
}
35+
return(sum%3==0);
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This program ask the user to enter the number of dits in a binary number and then wants the the user to enter that number and then checks whether the entered binary number is a multiple of 3 or not.

0 commit comments

Comments
 (0)