I am a C beginner and I tried to write a program to convert numbers from decimal base to octal. The program is not working for higher numbers and for those between 192 and 2890(both included). For the numbers in that range, it displays octal value one less than the correct one and for higher numbers, it displays octal value one greater.

Please tell me what is wrong with my code.

I am using Codelite.

Thanks.

Code: C

#include <stdio.h>

#include <math.h>

int main()

{

int quo, rem, inp, oct=0;

printf("Input the number(positive integer only)\n");

scanf("%d", &inp);

quo=inp;

for(int i=0;quo!=0;i++)

{

rem=quo%8;

quo=quo/8;

oct=oct+(pow(10, i)*rem);

}

printf("The octal equivalent of %d is = %d\n", inp, oct);

main();

return 0;

}

Please tell me what is wrong with my code.

I am using Codelite.

Thanks.