Labels
- 2-3Tree (1)
- 2-3Tree@ADS(EXP3) (1)
- ADS (6)
- ADS@Exp1 (1)
- ADS@Exp2 (1)
- ADS@Exp3 (1)
- ADSLAB (1)
- AVL TREE (2)
- AVL-Tree@ADS(EXP2) (1)
- B-Tech (1)
- CNS (1)
- cp for area of triangle (1)
- cpexp1a (1)
- CSE (2)
- CSE FOSS (1)
- CUT) (1)
- DAA (1)
- DECIMAL TO BINARY (1)
- FOSS (4)
- FOSS LAB SYLLABUS (1)
- FOSS@EXP2(CAT (1)
- FOSS@EXP3 (1)
- HASHING (2)
- JNTUK@ADS LAB (3)
- JNTUKR13REGULATION (1)
- ONES COMPLEMENT (1)
- PASTE (1)
- R13 FOSS LAB (1)
- SED (FOSS command) (1)
- SHELL (foss COMMAND) (1)
- TWO'S COMPLEMENT (1)
C-program to find binary number
for given decimal number and its one’s complement and two’s complement
|
||
#include<stdio.h>
#include<conio.h>
void
main(){
int
n,h,r,count=0,c=0,tem[10],b[10],o[10],t[10],i,j=0;
clrscr();
printf("Enter
the Decimal Number: ");
scanf("%d",&n);
h=n;
|
||
printf("\n
The Binary number for %d is: ",h);
i=0;
while(n>0){
r=n%2;
tem[i]=r;
i++;
c++;
n=n/2;
}
for(i=c-1;i>=0;i--){
b[j]=tem[i];
j++;
}
for(i=0;i<j;i++){
printf("%d",b[i]);
}
|
printf("\n
1’s com of %d is : ",h);
for(i=0;i<j;i++){
if(b[i]==0)
o[i]=1;
else
o[i]=0;
}
for(i=0;i<j;i++)
printf("%d",o[i]);
|
printf("\n
Tow's complement of %d is:",h);
for(i=j-1;i>=0;i--){
if(count==0
&& b[i]==1){
t[i]=1;
count++;
}
else
if(count==0 && b[i]==0){
t[i]=b[i];
}
else
{
if(b[i]==1)
t[i]=0;
else t[i]=1;
}//else
}//for
for(i=0;i<j;i++)
printf("%d",t[i]);
|
getch();
}
|
||
Output:
|
Labels:
DECIMAL TO BINARY,
ONES COMPLEMENT,
TWO'S COMPLEMENT
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment