Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebd9398

Browse files
authored
decimal to binary without function use
1 parentebc7892 commitebd9398

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

‎Conversions/decimal _to_binary.c

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
1-
/*********decimal number to binary number conversion*****************/
2-
#include<stdio.h>
3-
voiddecimal2Binary(longnum);
4-
5-
intmain(){
6-
7-
longnum;
8-
9-
printf("Enter a decimal integer \n");
10-
scanf("%ld",&num);
11-
decimal2Binary(num);
12-
13-
return0;
14-
}
15-
16-
/***function for convert decimal numbers to binary numbers****************/
17-
voiddecimal2Binary(longnum){
18-
19-
longdecimal_num,remainder,base,binary,no_of_1s;
20-
21-
base=1;
22-
binary=0;
23-
no_of_1s=0;
1+
#include<stdio.h>
2+
intmain()
3+
{
4+
intn,re,a[10000],j;
5+
printf("\nenter the no ");
6+
scanf("%d",&n);
7+
inti=0;
8+
while(n>0)
9+
{
2410

25-
while (num>0)
11+
re=n%2;
12+
a[i]=re;
13+
n=n/2;
14+
i++;
15+
}
16+
intk;
17+
k=i-1;
18+
printf("\n the number in binary is: ");
19+
for(j=k;j>=0;j--)
2620
{
27-
remainder=num %2;
28-
29-
if (remainder==1)
30-
{
31-
no_of_1s++;
32-
}
33-
binary=binary+remainder*base;
34-
num=num /2;
35-
base=base*10;}
36-
37-
printf("Its binary equivalent is = %ld\n",binary);
21+
printf("%d",a[j]);
22+
}
23+
return(0);
3824
}
25+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp