Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <float.h>
  5.  
  6. FILE *fichier;
  7. float rep[3000]={0},data[1000],som=5,*ptab,arr[1000];
  8. int sauv[200];
  9. int cptrep=0,n,cpttest=0;
  10. void Affichage();
  11. void combinationUtil(int r,int index,int i);
  12. void testcombi();
  13. void aprintCombination(int r)
  14. {
  15.     float tempo;
  16.     int y=0,bou,bou1;
  17.  
  18.     ptab=(float *)malloc(1000);
  19.     bou=0;
  20.     while(bou<=n)//tri
  21.     {
  22.         bou1=bou+1;
  23.         while(bou1<n+1)
  24.         {
  25.             if(arr[bou]>arr[bou1])
  26.             {
  27.                 tempo=arr[bou];
  28.                 arr[bou]=arr[bou1];
  29.                 arr[bou1]=tempo;
  30.             }
  31.             bou1++;
  32.         }
  33.         printf("%.2f\n",arr[bou]);
  34.         bou++;
  35.     }
  36.  
  37.  
  38.     printf("saisissez la somme: \n");//saisie de la somme
  39.     //fflush(stdin);
  40.     //scanf("%f",&som);
  41.     //som=5;
  42.  
  43.     while((arr[0]+arr[y])<=som && y<=r) //coupe le vecteur a la valeur somme rentée
  44.     {
  45.         y++;
  46.  
  47.     }
  48.     bou1=0;
  49.     while(bou1<=100)
  50.     {
  51.         sauv[bou1]=-1;
  52.         bou1++;
  53.     }
  54.     r=y;
  55.     n=r;
  56.     testcombi();
  57.     //Affichage();
  58. }
  59.  
  60.  
  61. int boucle(int numeroactuel,int taille,int taillerech,int somactuel)
  62. {
  63.     int retour=0,bou=numeroactuel+1,somtest,bou1=0,tmp=0;
  64.     //cpttest++;
  65.     //printf("%d\n",cpttest);
  66.  
  67.     if(numeroactuel<=n && taillerech<=taille)
  68.     {
  69.         somtest=somactuel-arr[numeroactuel];
  70.         while(taillerech<=taille && bou<=n)
  71.         {
  72.             retour+=boucle(bou,taille,taillerech+1,somtest);
  73.             sauv[taillerech]=numeroactuel;
  74.             if(retour==somtest)
  75.             {
  76.                 retour+=arr[numeroactuel];
  77.  
  78.                 sauv[0];
  79.                 sauv[1];
  80.                 sauv[2];
  81.                 sauv[3];
  82.                 sauv[4];
  83.                 sauv[5];
  84.  
  85.                 if(taillerech==0 && sauv[taillerech] )//on est au premier nombre de ma combianaison
  86.                 {
  87.                     bou1=0;
  88.                     while(sauv[bou1]!=-1)
  89.                     {
  90.                         tmp=sauv[bou1];
  91.                         printf("%.2f ",arr[tmp]);
  92.                         bou1++;
  93.                     }
  94.                     printf("\n");
  95.                 }
  96.                 else
  97.                 {
  98.                     return retour;//on retourne a 0
  99.                 }
  100.                 retour=0;
  101.             }
  102.             else
  103.             {
  104.                 bou1=0;
  105.                 while(bou1<100)
  106.                 {
  107.                     sauv[bou1]=-1;
  108.                     bou1++;
  109.                 }
  110.             }
  111.  
  112.             bou++;
  113.         }
  114.  
  115.     }
  116.     else
  117.     {
  118.         return 0;
  119.     }
  120.  
  121. }
  122.  
  123. void testaffi()
  124. {
  125.     printf("find\n");
  126. }
  127.  
  128. void testcombi()
  129. {
  130.     int cpt=0,cpt1=0,bou=0,i=0,taille=1;
  131.  
  132.     int rep=0;
  133.  
  134.     while(taille<=n)
  135.     {
  136.         bou=0;
  137.         while(bou<=n)
  138.         {
  139.             rep=boucle(bou,taille,0,som);
  140.             bou++;
  141.         }
  142.         taille++;
  143.     }
  144.  
  145. }
  146. void Affichage()
  147. {
  148.     fichier=fopen("rep.csv","a");
  149.     int cpttmp=0;
  150.     if(fichier!=NULL)
  151.     {
  152.         while(rep[cpttmp]!=(-FLT_MAX))//tant qu'il est pas la fin du vect
  153.         {
  154.             while(rep[cpttmp]!=(FLT_MAX))//tant qu'il est pas la fin d'une ligne du vect
  155.             {
  156.                 printf("%.2f ",rep[cpttmp]);
  157.                 cpttmp++;
  158.             }
  159.             printf("\n");
  160.             cpttmp++;
  161.  
  162.         }
  163.         fclose(fichier);
  164.     }
  165.  
  166. }
  167. int main()
  168. {
  169.     FILE* fichier;
  170.     char tampon[1000],c;
  171.     int actuel=0;
  172.     int bou,n;
  173.     int r,t;
  174.     unsigned long o=1;
  175.  
  176.     //remplissage de va par les chiffre du fichier
  177.     fichier = fopen("fic.csv","r");
  178.     if (fichier != NULL) // ok
  179.     {
  180.         bou=0;
  181.  
  182.          while ((c = fgetc (fichier)) != EOF)
  183.          {
  184.                 if (c == ';' || c == '\n')
  185.                 {
  186.                         arr[bou]=strtof (tampon, NULL);
  187.                         actuel = 0;
  188.                         memset (tampon, 0, sizeof tampon);
  189.                         r=bou;
  190.                         bou++;
  191.                 }
  192.                 else
  193.                 {
  194.                     if (c ==',')
  195.                     {
  196.                         tampon[actuel++]='.';
  197.                     }
  198.                     else
  199.                     {
  200.                        tampon[actuel++] = c;
  201.                     }
  202.                 }
  203.         }
  204.         fclose(fichier);
  205.     }
  206.     else
  207.     {
  208.         printf("pas de fichir a ouvrir");
  209.         return 0;
  210.     }
  211.     fichier =fopen("rep.csv","w");
  212.     fclose(fichier);
  213.     t=r;
  214.     n = r;
  215.  
  216.     aprintCombination( r);
  217.     return 0;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement