Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

82
Visualizações
How I do this in switch statement

Convert the following codes into switch statement:

int a = 5, b = 10, c = 15, choice;
choice = a > b && a>c ? a: (b > c ? b: c);
printf(“%d”, choice);

I try this way.

#include<stdio.h>
int main()
{
    int a = 5, b = 10, c = 15, choice;
    switch(choice)
    {
       case 'a > b && a>c':
       {
           choice=a;
           break;
       }
       case 'b > c':
       {
           choice=b;
           break;
       }
       default :
       {
           choice=c;
           break;
       }    
    }
    printf("%d",choice);    
}

but its output always come C. If I give a=15,b=10,c=5 output comes out 5 wheres it should be 15. Where I did wrong??

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You want largest of (a, b, c) to be the choice. switch(logical-condition) evaluates to either true or false.

It's not recommended to use switch in this scenario. However, for the learning angle:

#include <stdbool.h> // for true/false flags

    switch (a > b) {
    case true :
        switch (a > c) {
        case true:
            choice = a;
            break;
        case false:
            choice = c;
            //break;    //redundant
        }
        break;
    case false:
        switch (b > c) {
        case true:
            choice = b;
            break;
        case false :
            choice = c;
            //break;    //redundant
        }
        //break;    //redundant
    }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda