- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include "stack.h"
- int main(void)
- {
- int num;
- char alpha;
- int* digit;
- STACK* stack;
- stack = createStack ();
- printf("Please enter your integer (decimal): \n");
- scanf("%d" , &num);
- while(num > 0)
- {
- digit = (int*) malloc (sizeof(int));
- *digit = num % 16;
- push (stack, digit);
- num = num/16;
- }
- while (!emptyStack (stack))
- {
- digit = (int*)popStack (stack);
- if(*digit > 9)
- {
- if(*digit == 10)
- alpha = 'A';
- else if(*digit == 11)
- alpha = 'B';
- else if(*digit == 12)
- alpha = 'C';
- else if (*digit == 13)
- alpha = 'D';
- else if (*digit == 14)
- alpha = 'E';
- else if (*digit == 15)
- alpha = 'F';
- }
- printf("%c", alpha);
- else
- printf("%d", digit);
- }
- destroyStack(stack);
- return 0;
- }
c programming basic's
Wednesday, 14 December 2011
convert decimal number to hexadecimal in c programming
Subscribe to:
Posts (Atom)