Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////
- //
- // VOTRE NOM : CAPOZZA
- // VOTRE PRENOM : Vito
- //
- /////////////////////////////////////////////////
- //Vous pouvez tester les fonctions du main que vous avez écrites en exécutant le programme CodNum.exe
- #include <stdio.h>
- #include <stdlib.h>
- // Nombre maximum de bits codant toute donnée
- #define NBMAX 32
- //initialisation les n éléments du tableau t avec des 0
- void InitTab(int n, int t[])
- {
- int i;
- for (i = 0; i < n-1; i++)
- t[i] = 0;
- }
- // Lit le code en complement à b (1 ou 2) sur n positions d'un nombre
- void LireTab(int n, int t[])
- {
- int i;
- for (i = 0; i < n; i++){
- scanf("%d", &t[i]);
- }
- }
- // Affichage sans passage à la ligne d'un tableau t de n bits
- void AfficherTab(int n, int t[])
- {
- int i;
- for (i = 0; i < n; i++)
- printf("%d", t[i]);
- printf("\n");
- }
- //inversion des n elements du tableau t
- void InverserTableau(int n, int t[])
- {
- int i, reverse;
- int j = n-1;
- for (i = 0; i != j/2; i++) {
- reverse = t[i];
- t[i] = t[j];
- t[j] = reverse;
- j--;
- }
- }
- //Convertit un entier positif val en binaire pur sur n positions
- void Int2Bin(int val, int n, int t[])
- {
- int i, reverse, reste;
- int j = n-1;
- for (i = 0; i < n-1; i++){
- t[i] = 0;
- }
- for (i=0; val>0, i< n-1; i++){
- t[i] = val%2;
- val = val/2;
- }
- InverserTableau(n, t);
- }
- // Calcule le complement a 1 de l'entier val
- void ComplementA1(int val, int n, int t[])
- {
- //A completer
- }
- // Calcule le complement a 2 de l'entier val
- void ComplementA2(int val, int n, int t[])
- {
- //A completer
- }
- //Retourne la valeur entiere d'un binaire en complement a b sur n positions
- int ValBin(int b, int n, int t[])
- {
- //A completer
- }
- int main()
- {
- int choix, valeur;
- int continuer = 1;
- int n = 16;
- int val = 77;
- int base;
- int tab[NBMAX];
- char* menu =
- " \n\nProgramme de test\n\n0 Quitter\n1 ComplementA1(valeur, n, tab)\n2 ComplementA2(valeur, n, tab)\n3 ValBin(base, n, tab)\n\n";
- char* invite = "--> Quel est votre choix ? ";
- Int2Bin(val, 32, tab);
- printf("%s", menu);
- while (continuer == 1) {
- printf("%s", "--> Quel est votre choix ? ");
- scanf("%d", &choix);
- switch (choix) {
- case 0:
- continuer = 0;
- break;
- case 1:
- printf("Entrez un nombre : ");
- scanf("%d", &valeur);
- ComplementA1(valeur, n, tab);
- AfficherTab(n, tab);
- break;
- case 2:
- printf("Entrez un nombre : ");
- scanf("%d", &valeur);
- ComplementA2(valeur, n, tab);
- AfficherTab(n, tab);
- break;
- case 3:
- printf("Entrez le code du nombre : ");
- LireTab(n, tab);
- printf("Entrez la base : ");
- scanf("%d", &base);
- printf("C'est le code de %d\n", ValBin(base, n, tab));
- break;
- case 4:
- printf("Entrez le code du nombre :");
- scanf("%d", &valeur);
- Int2Bin(valeur, n, tab);
- AfficherTab(n, tab);
- break;
- default:
- printf("Choix inexistant !!!!\n");
- printf("%s", menu);
- }
- }
- printf("Au revoir et a bientot\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement