Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C-program to Convert the octal number into decimal and Vice-Versa



In this C-program we will Convert the Octal Number into Decimal number and Decimal Number into Octal Number. The number will be taken from the user.color>

input:

The number.(i.e : 5,6,9[Decimal Number] or 12,57,567[Octal Number] etc.)

output:

Octal number will be converted into Decimal number OR Decimal number will be converted into Octal number.

CODE---->


#include
#include
#include
color>main()color>
{
int oct_num,oct,dec_num,dec,remainder,i,n;
printf("***************Welcome to Converter***************color>");
printf("\n\n\n1.Octal to Decimal\n\n2.Decimal to Octal\n\n Enter Your choice : color>");
scanf("%dcolor>",&n);
switch(ncolor>)
{
case 1color>:
printf("\nPlease, Enter the Octal number : color>");
scanf("%dcolor>",&oct_num);
oct=oct_num;
i=0;
dec=0;
while(oct_num!=0color>)
{
remainder=oct_num%10;
dec=dec+remainder*pow(8color>,icolor>);
i++;
oct_num=oct_num/10;
}
printf("\nThe decimal of %d is : %dcolor>",oct,dec);
break;
case 2color>:
printf("\nPlease, Enter the Decimal number : color>");
scanf("%dcolor>",&dec_num);
dec=dec_num;
i=1;
oct=0;
while(dec_num!=0color>)
{
remainder=dec_num%8;
dec_num=dec_num/8;
oct=oct+remainder*i;
i=i*10;
}
printf("\nThe octal of %d is : %dcolor>",dec,oct);
break;
default:
printf("\n SORRY !!! You have Entered a wrong choice.color>");
break;
}
getch();
}



Don't just read, write it, run it.....color>

RESULT:color>






This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

C-program to Convert the octal number into decimal and Vice-Versa

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×