criar 3 algoritimos que imprima vetores em duplas usando for, ou if.
Soluções para a tarefa
Resposta:
int A[9] = {5,5,10,10,10,22,22,33,43};
int B[15] = {5,5,5,10,10,10,20,20,20,20,40,40,40,55,55,};
int C[21] = {7,7,8,9,10,10,10,12,15,20,25,25,25,25,43,34,43,56,56,56,90};
int i,j, count, lowcount, current;
//Organizar os vetores
//A
for(i = 0; i < 9; i++)
{
for(j = i +1; j < 9; j++)
{
if(A[i] < A[j])
{
int aux = A[i];
A[i] = A[j];
A[j] = aux;
}
}
}
//B
for(i = 0; i < 15; i++)
{
for(j = i +1; j < 15; j++)
{
if(B[i] < B[j])
{
int Bux = B[i];
B[i] = B[j];
B[j] = Bux;
}
}
}
//C
for(i = 0; i < 21; i++)
{
for(j = i +1; j < 21; j++)
{
if(C[i] < C[j])
{
int Cux = C[i];
C[i] = C[j];
C[j] = Cux;
}
}
}
//Buscar e contar nos vetores
//A
for(i = 0 ; i<9;i++)
{
printf("%i ", A[i]);
if(A[i]!=current)
{
lowcount = 0;
current = A[i];
}
if(A[i] == current)
{
lowcount++;
}
if(lowcount == 2)
{
lowcount = 0;
count++;
}
}
printf("Quantidade de Duplas: %i\n", count);
count = 0;
//B
for(i = 0 ; i<15;i++)
{
printf("%i ", B[i]);
if(B[i]!=current)
{
lowcount = 0;
current = B[i];
}
if(B[i] == current)
{
lowcount++;
}
if(lowcount == 2)
{
lowcount = 0;
count++;
}
}
printf("Quantidade de Duplas: %i\n", count);
count = 0;
//C
for(i = 0 ; i<21;i++)
{
printf("%i ", C[i]);
if(C[i]!=current)
{
lowcount = 0;
current = C[i];
}
if(C[i] == current)
{
lowcount++;
}
if(lowcount == 2)
{
lowcount = 0;
count++;
}
}
printf("Quantidade de Duplas: %i\n", count);
return 0;
Got it, thanks!Thanks a lot.Thank you!
Explicação: