Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- void inHexa(long int n) {
- int i = 1, j, temp, r, q;
- char numarHexadecimal[100];
- q = n;
- while (q != 0) {
- temp = q % 16;
- //Convertim numarul intreg in caracter
- if (temp < 10) {
- temp = temp + 48;
- }
- else {
- temp = temp + 55;
- }
- numarHexadecimal[i++] = temp;
- q = q / 16;
- }
- printf("\nNumarul %d in hexadecimal este ", n);
- for (j = i - 1; j > 0; j--)
- printf("%c.", numarHexadecimal[j]);
- }
- void inBinar(int n) { // prin recursivitate, convertim numarul in baza 2
- if (n / 2 != 0) {
- inBinar(n / 2);
- }
- printf("%d", n % 2);
- }
- void main() {
- AGAIN:
- long int n;
- char conversie, continuare;
- int i = 1, j, temp;
- char numarHexadecimal[100];
- printf("Introduceti un numar: \n");
- scanf_s("%ld", &n);
- printf("Introduceti tasta: \n~\"o\" - octal \n~\"h\" - hexadecimal:\n~\"b\" - binar\n");
- conversie = _getch();
- if (conversie == 'o') {
- printf("\nNumarul %d in octal este %o .", n, n);
- }
- else
- if (conversie == 'h') {
- inHexa(n);
- }
- else if (conversie == 'b') {
- printf("\nNumarul %d in binar este: ", n);
- inBinar(n);
- }
- else {
- printf("\nVa rog sa reintroduceti tasta!");
- conversie = getchar();
- }
- printf("\n\nDoriti sa reluati programul?(y/any key)");
- continuare = _getch();
- if (continuare == 'y') {
- system("CLS");
- goto AGAIN;
- }
- else {
- exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement