Okay, was mache ich hier falsch?Seltsame Array-Ausgaben
Dieses Programm soll 20 Ganzzahlen lesen und dann ein Array der Ganzzahlen ausgeben, die keine Duplikate sind (Ausgabe jeder Ganzzahl nur einmal).
//Program to read 20 integers and return each integer only once (no duplicates).
#include <stdio.h>
int main()
{
int a, b, count=0, temp, array1[20];
printf("Enter 20 array elements between 1 and 10 inclusive\n");
for (a=0; a<20; a++) //Loop to enter 20 elements
{
scanf("%d", &temp);
for (b=0; b<=20; b++) //Loop to test each new element against all previous entered elements
{
if (array1[b] == temp) //If duplicate increment count
{
count++;
}
else if (count == 0 && b == 20) //If there have been no duplicates and 20 numbers have been tested... add entered number to the array
{
array1[a] = temp;
}
}
}
for (a=0; a<20; a++)
{
printf("%d\t", array1[a]);
}
return 0;
}
Was sind Ihre Eingaben? Was hast du als Output gesehen? – skrrgwasme
Wenn ich zum Beispiel 1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1,2 eingeben. Ich bekomme die Ausgabe: 4200256, 0, 24, 0, 7344944, 0, 1, 0, -1, -1, 4200357, 0, 1, 0, 4200 233, 0, 0, 0, 24, 0 –
@JakeRitter Bitte geben Sie alle Informationen in die Frage ein, indem Sie sie bearbeiten und nicht in Kommentaren. –