im looking for nice and clean way to see if there are three equal numbers in an array.
Right now i have this:
for (int i = 0; i < nr ; i++)
{
if(a[i] == 1){one++;}
else if(a[i] == 2){two++;}
else if(a[i] == 3){three++;}
else if(a[i] == 4){four++;}
else if(a[i] == 5){five++;}
else if(a[i] == 6){six++;}
}
if(one >= 3){
printf("Tre tal finns i ettor, 3p\n");
}else if(two >= 3){
printf("Tre tal finns i tvår, 6p\n");
}else if(three >= 3){
printf("Tre tal finns i treor, 9p\n");
}else if(four >= 3){
printf("Tre tal finns i fyror, 12p\n");
}else if(five >= 3){
printf("Tre tal finns i femmor, 15p\n");
}else if(six >= 3){
printf("Tre tal finns i sexor, 18p\n");
}
Where a (integer) is an array of 5 elements(containing elemets 1-6) and "nr" is an variable to keep track for the arrays length.
If anyone got a nicer and better way to do this, please reply.