Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////
- //
- // VOTRE NOM : El Aaqdi
- // VOTRE PRENOM : Aiman
- //
- /////////////////////////////////////////////////
- //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; 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, t_tmp[n];
- for (i =0;i<n;i++)
- t_tmp[n-1-i] = t[i];
- i = 0;
- for (i = 0; i< n; i++)
- t[i] = t_tmp[i];
- }
- //Convertit un entier positif val en binaire pur sur n positions
- void Int2Bin(int val, int n, int t[])
- {
- int j, i = 0, x = 1;
- while(val > 0) {
- t[n - x] = val % 2;
- val = val / 2;
- i++;
- x = i + 1;
- }
- }
- // Calcule le complement a 1 de l'entier val
- void ComplementA1(int val, int n, int t[])
- {
- Int2Bin(val, n, t);
- int i;
- for (i = 0; i < n; i++)
- (t[i]== 0) ? (t[i] = 1) : (t[i] = 0);
- }
- // Calcule le complement a 2 de l'entier val
- void ComplementA2(int val, int n, int t[])
- {
- int i, carry = 1;
- ComplementA1(val, n, t);
- }
- //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 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)\n4 InverserTableau(n, tab)\n5 Int2Bin(valeur, n, tab)\n";
- char* invite = "--> Quel est votre choix ? ";
- 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:
- LireTab(n, tab);
- printf("Tableau inverse\n");
- InverserTableau(n, tab);
- AfficherTab(n, tab);
- break;
- case 5:
- printf("Entrez un nombre : ");
- scanf("%d", &valeur);
- Int2Bin(valeur, n, tab);
- AfficherTab(n, tab);
- 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