-1

I want a c program which ask for Hexadecimal number and gives output equivalent octal number. I use the code to convert int into octal using printf() function.

#include<stdio.h>
Void main(){
  int i;
  printf("Enter the Hax number: ");
  scanf("%x",&i);
  printf("Octal equivalent of number is %o",i);
}
Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
Max
  • 5,733
  • 4
  • 30
  • 44

2 Answers2

1

Hexadecimal and Octal are just different representations of the same underlying number format. ie binary. So no conversion is really happening in your example. Its just that you are interpreting/printing the same number in 2 different ways. And printf is indeed doing a good job in your example

Enter the Hax number: FF
Octal equivalent of number is 377

The only other problematic thing I can see is Void main :)

Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
  • yes u r right but printf() does not convert the actual value i holds. I want to convert this value – Max Sep 04 '12 at 05:11
1

other than your syntax errors this seems to be working, I just copied it. change

Void main()

to

int main() 

or

//Since you are not using command line arguments this isn't necessary but valid
int main(int argc, char **argv)

and add a

return 0; //not necessary but good practice

at the end of the method

EDIT:

also

void main() 

will compile with many C compilers, but is invalid C (no current and prior standard sanctions it). Use int instead.

Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
twain249
  • 5,666
  • 1
  • 21
  • 26