Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void exo7()
- {
- //Convert binary to decimal
- int n;
- printf("Entrer un nombre en binaire.\n");
- scanf("%d", &n);
- int old_n = n;
- int decimalNumber = 0, i = 0, temp;
- while(n != 0)
- {
- temp = n%10;
- n /= 10;
- decimalNumber += temp*pow(2, i);
- i++;
- }
- printf("%d in decimal is %d\n\n", old_n, decimalNumber);
- printf("Entrer un nombre decimal entier.\n");
- scanf("%d", &decimalNumber);
- int old_dec = decimalNumber;
- i = 1, n = 0;
- while(decimalNumber != 0)
- {
- temp = decimalNumber%2;
- decimalNumber /= 2;
- n += temp * i;
- i *= 10;
- }
- printf("%d in binary is %d", old_dec, n);
- }
- void exo8()
- {
- int decimal, octal = 0, i = 0, temp;
- printf("Entrer un nombre decimal entier.\n");
- scanf("%d", &decimal);
- printf("%d in octal is ", decimal);
- while(decimal != 0)
- {
- temp = decimal%8;
- decimal /= 8;
- octal += temp*pow(8, i);
- i++;
- }
- printf("%d", octal);
- }
- int main()
- {
- exo8();
- return 0;
- }
Add Comment
Please, Sign In to add comment