Thursday, 26 October 2017

Binary To Octal

#include<stdio.h>
int main(int argc,char *argv[])
{
int bin,rem,j=1,octnum=0;
if(argc!=2)
exit(1);
bin=atoi(argv[1]);
while(bin!=0)
{
rem=bin%10;
octnum=octnum+rem*j;
j=j*2;
bin=bin/10;
}
printf("Equivalent octal value: %o",octnum);
return 0;
}

Contributed by Priti Lohia

No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...