Monday, June 24, 2013

Write a program to convert Decimal to Octal?

Problem:

To convert the given decimal no into octal without using in build function ,Example 26  shoule printed as 32

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,intex[]={0,1,2,3,4,5,6,7},data[100],i=0,j;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\nthe %d to octal is ",a);

while(a!=0)
{
data[i]=a%8;
i++;
a=a/8;
}
for(i--;i>=0;i--)
{
j=data[i];
printf("%d",intex[j]);
}
getch();
}


Output:



Like the Post? Do share with your Friends.

No comments:

Post a Comment