Skip to content
Snippets Groups Projects
Select Git revision
  • 85cb4e906992e104b9b05f00e8c0cb6f57fb3357
  • main default protected
2 results

main.c

Blame
  • main.c 2.04 KiB
    /*
        Autheur		: Abivarman KANDIAH
        Date		: 10/11/2021
        Fichier		: main.c
        Descritpion : Manipulation de tableau avec alloc dynamique
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <math.h>
    #include <time.h>
    #include "../header/tab_uni_malloc.h"
    
    int main()
    {
        printf("Tableaux unidimensionnels et allocation dynamique de mémoire \n");
        
        //1.
        u_int64_t size;
        printf("Entrez la taille du tableau : \n");
        scanf(" %lu", &size);
    
        // Allocation dynamique
        int64_t *tab = malloc(sizeof(int64_t) * size);
    
        //2.
        FillTabWithIndex(tab, size);
        RandomSwapTab(tab, size);
    
        //3.
        PrintTableau(tab, size);
    
        //4.
        RandomSwapTab(tab, size);
        PrintTableau(tab, size);
        //5.
        CyclicSwapTab(tab, size, 2);
        PrintTableau(tab, size);
    
        //6.
        Swap(&tab[FindLowIndex(tab, size)], &tab[size-1]);
        PrintTableau(tab, size);
    
        //7.
        TriInsertionDescent(tab, size);
        PrintTableau(tab, size);
    
        //8.
        int64_t input_value = 0;
        printf("\nEntrez une valeur : \n");
        scanf(" %ld", &input_value);
        printf("Il y a %ld d'élements plus petit que %ld dans le tableau. \n", FindHowManySmaller(tab,size, input_value),input_value);
    
        //9. 
        int64_t *tab_two = malloc(sizeof(int64_t) * size);
        int64_t *tab_three = malloc(sizeof(int64_t) * size);
        FillTabWithIndex(tab_two, size);
        RandomSwapTab(tab_two, size);
        PrintTableau(tab, size);
        PrintTableau(tab_two, size);
        SumOfTab(tab, tab_two, tab_three, size);
        PrintTableau(tab_three, size);
    
        //10.
        int64_t *tab_four = malloc(sizeof(int64_t) * size);
        printf("\nEntrez une valeur : \n");
        scanf(" %ld", &input_value);
        TabTimesN(tab_three, input_value, tab_four, size);
        PrintTableau(tab_four, size);
        
        //11.
        double *tab_five = malloc(sizeof(double) * size);
        ConvertTabToDouble(tab_four, tab_five, size);
        PrintTableauDouble(tab_five, size);
        
        //Free the Malloc
        free(tab);
        free(tab_two);
        free(tab_three);
        free(tab_four);
        free(tab_five);
    
        return 0;
    }