Monday, July 2, 2018

C: Program to convert Octal number to Decimal equivalent

#include<stdio.h>
#include<math.h>
int main()
{int octal,copy_of_octal,qoutient,number_of_digits=0,copy_of_number_of_digits=0,Decimal_equivalent=0,j=0;
printf("Enter any octal number\n");
scanf("%d",&octal);
copy_of_octal=octal;
while(qoutient!=0)
{
    qoutient=octal/10;
    octal=qoutient;
    number_of_digits++;
}
copy_of_number_of_digits=number_of_digits;
int d[number_of_digits];
while(number_of_digits!=0)
{
    d[j]=copy_of_octal%10;
    copy_of_octal=copy_of_octal/10;
    j++;
    number_of_digits--;
}
for(int k=0;k<copy_of_number_of_digits;k++)
{
     Decimal_equivalent+= d[k]*pow(8,k);

}
 printf("Decimal equivalent of entered octal number is %d ",Decimal_equivalent);
return 0;
}

No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows