Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <float.h>
- FILE *fichier;
- float rep[3000]={0},data[1000],som=5,*ptab,arr[1000];
- int sauv[200];
- int cptrep=0,n,cpttest=0;
- void Affichage();
- void combinationUtil(int r,int index,int i);
- void testcombi();
- void aprintCombination(int r)
- {
- float tempo;
- int y=0,bou,bou1;
- ptab=(float *)malloc(1000);
- bou=0;
- while(bou<=n)//tri
- {
- bou1=bou+1;
- while(bou1<n+1)
- {
- if(arr[bou]>arr[bou1])
- {
- tempo=arr[bou];
- arr[bou]=arr[bou1];
- arr[bou1]=tempo;
- }
- bou1++;
- }
- printf("%.2f\n",arr[bou]);
- bou++;
- }
- printf("saisissez la somme: \n");//saisie de la somme
- //fflush(stdin);
- //scanf("%f",&som);
- //som=5;
- while((arr[0]+arr[y])<=som && y<=r) //coupe le vecteur a la valeur somme rentée
- {
- y++;
- }
- bou1=0;
- while(bou1<=100)
- {
- sauv[bou1]=-1;
- bou1++;
- }
- r=y;
- n=r;
- testcombi();
- //Affichage();
- }
- int boucle(int numeroactuel,int taille,int taillerech,int somactuel)
- {
- int retour=0,bou=numeroactuel+1,somtest,bou1=0,tmp=0;
- //cpttest++;
- //printf("%d\n",cpttest);
- if(numeroactuel<=n && taillerech<=taille)
- {
- somtest=somactuel-arr[numeroactuel];
- while(taillerech<=taille && bou<=n)
- {
- retour+=boucle(bou,taille,taillerech+1,somtest);
- sauv[taillerech]=numeroactuel;
- if(retour==somtest)
- {
- retour+=arr[numeroactuel];
- sauv[0];
- sauv[1];
- sauv[2];
- sauv[3];
- sauv[4];
- sauv[5];
- if(taillerech==0 && sauv[taillerech] )//on est au premier nombre de ma combianaison
- {
- bou1=0;
- while(sauv[bou1]!=-1)
- {
- tmp=sauv[bou1];
- printf("%.2f ",arr[tmp]);
- bou1++;
- }
- printf("\n");
- }
- else
- {
- return retour;//on retourne a 0
- }
- retour=0;
- }
- else
- {
- bou1=0;
- while(bou1<100)
- {
- sauv[bou1]=-1;
- bou1++;
- }
- }
- bou++;
- }
- }
- else
- {
- return 0;
- }
- }
- void testaffi()
- {
- printf("find\n");
- }
- void testcombi()
- {
- int cpt=0,cpt1=0,bou=0,i=0,taille=1;
- int rep=0;
- while(taille<=n)
- {
- bou=0;
- while(bou<=n)
- {
- rep=boucle(bou,taille,0,som);
- bou++;
- }
- taille++;
- }
- }
- void Affichage()
- {
- fichier=fopen("rep.csv","a");
- int cpttmp=0;
- if(fichier!=NULL)
- {
- while(rep[cpttmp]!=(-FLT_MAX))//tant qu'il est pas la fin du vect
- {
- while(rep[cpttmp]!=(FLT_MAX))//tant qu'il est pas la fin d'une ligne du vect
- {
- printf("%.2f ",rep[cpttmp]);
- cpttmp++;
- }
- printf("\n");
- cpttmp++;
- }
- fclose(fichier);
- }
- }
- int main()
- {
- FILE* fichier;
- char tampon[1000],c;
- int actuel=0;
- int bou,n;
- int r,t;
- unsigned long o=1;
- //remplissage de va par les chiffre du fichier
- fichier = fopen("fic.csv","r");
- if (fichier != NULL) // ok
- {
- bou=0;
- while ((c = fgetc (fichier)) != EOF)
- {
- if (c == ';' || c == '\n')
- {
- arr[bou]=strtof (tampon, NULL);
- actuel = 0;
- memset (tampon, 0, sizeof tampon);
- r=bou;
- bou++;
- }
- else
- {
- if (c ==',')
- {
- tampon[actuel++]='.';
- }
- else
- {
- tampon[actuel++] = c;
- }
- }
- }
- fclose(fichier);
- }
- else
- {
- printf("pas de fichir a ouvrir");
- return 0;
- }
- fichier =fopen("rep.csv","w");
- fclose(fichier);
- t=r;
- n = r;
- aprintCombination( r);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement