#include<stdio.h>
#include<conio.h>
#include<math.h>
float octal_conversion(int octal);
void main()
{
int octal,answer;
clrscr();
printf("program which convert octal to decimal\n\n");
printf("Enter a number in octal form= ");
scanf("%d",&octal );
answer = octal_conversion(octal);
if(answer == 8)
{
printf("wrong");
}
else
{
printf("The result is %d", answer);
}
getch();
}
float octal_conversion(int octal)
{
int square;
int remainder;
int i = 0;
int result=0 ;
while(octal > 0)
{
remainder = octal % 10;
square=pow(8,i);
if(remainder<=7)
{
result = result + square * remainder;
}
else
{
return 8;
}
octal = octal / 10;
i++;
}
return result;
}
No comments:
Post a Comment