Zahl nur ein mal ausgeben



  • Ich möchte das jede zahl nur max. einmal ausgegeben wird. Ber das funzt irgendwie nicht!

    #include <stdio.h>
    #include <conio.h>
    #include <time.h>
    #include <stdlib.h>
    
    void sortieren(int a[], int n)
    {
    	int i,j,min,temp;
    	for(i=0;i<n;i++)
    	{
    		min = i;
    		for(j=i+1;j>0 && j<n+1; j++)
    		{
    			if(a[j]<a[min])
    				min = j;
    		}
    		temp = a[min];
    		a[min]= a[i];
    		a[i] = temp;
    	}
    }
    int main(void)
    {
    	int array[6];
    	int i;
    	srand(time(NULL));
    
    	printf("Die Lottozahlen: ");
    	for(i=0; i < 6; i++)
    	{
    		array[i]= 1 + rand()%49;
    		printf("%i ", array[i]);
    	}
    	printf("\n");
    
    	sortieren(array, 6-1);
    
    	printf("Sortiert: ");
    	for(i=0; i<6;i++)
    	printf("%i ",array[i]);
    
    	printf("\n");
    	getch();
    	return 0;
    


  • Dann nehm ein printf() raus, jenachdem, ob du sortierte oder unsortierte Ausgabe willst.



  • DSD-Steve schrieb:

    Ich möchte das jede zahl nur max. einmal ausgegeben wird. Ber das funzt irgendwie nicht!

    #include <stdio.h>
    #include <conio.h>
    #include <time.h>
    #include <stdlib.h>
    
    void sortieren(int a[], int n)
    {
    	int i,j,min,temp;
    	for(i=0;i<n;i++)
    	{
    		min = i;
    		for(j=i+1;j>0 && j<n+1; j++)
    		{
    			if(a[j]<a[min])
    				min = j;
    		}
    		temp = a[min];
    		a[min]= a[i];
    		a[i] = temp;
    	}
    }
    int main(void)
    {
    	int array[6];
    	int i;
    	srand(time(NULL));
    
    	printf("Die Lottozahlen: ");
    	for(i=0; i < 6; i++)
    	{
    		array[i]= 1 + rand()%49;
    		printf("%i ", array[i]);
    	}
    	printf("\n");
    
    	sortieren(array, 6-1);
    
    	printf("Sortiert: ");
    	for(i=0; i<6;i++)
    	printf("%i ",array[i]);
    
    	printf("\n");
    	getch();
    	return 0;
    

    du solltest überprüfen, ob eine zufallszahl schon einmal erzeugt wurde.



  • Kannste bitte NUr den Ansatz mal posten? Auf die Lösung will ich selber kommen.



  • hat er doch gegeben: du solltest überprüfen, ob eine zufallszahl schon einmal erzeugt wurde.



  • @DSD-Steve
    Wie läuft es denn im richtigen Lotto ab?


Anmelden zum Antworten