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

177
Visualizações
How to use switch statement in c

How can I use switch statement in the following lines, as I don't want to make the if statement bulky.

if(uword1 == (65|69|73|76|78|79|82|83|84|85)) {
    total1++;
    printf("%i", total1);
}
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

  switch (uword1) {
    case 65:
    case 69:
    case 73:
    case 76:
    case 78:
    case 79:
    case 82:
    case 83:
    case 84:
    case 85:
        total1++;
        printf("%i", total1);
        break;
    default:
        break;
    }
over 4 years ago · Santiago Trujillo Relatório

0

Whether to use switch-case or if is a matter of taste. An if-statement will not get more "bulky" than the switch-case:

   if( uword1 == 65 ||
       uword1 == 69 ||
       uword1 == 73 ||
       uword1 == 76 ||
       uword1 == 78 ||
       uword1 == 79 ||
       uword1 == 82 ||
       uword1 == 83 ||
       uword1 == 84 ||
       uword1 == 85
   )
   {
       total1++;
       printf("%i", total1);
   }
over 4 years ago · Santiago Trujillo Relatório

0

For switch-case and if-statement both, the number of lines of code will be almost equal.

Here's how you do it in switch case:

switch(uword1)
    {
        case 65:
        case 69:
        case 73:
        case 76:
        case 78:
        case 79:
        case 82:
        case 83:
        case 84:
        case 85:
        total1++;
        printf("%i", total1);
        break;
        
        default:
        break;
    }

Here's the same code in if-statement:

if(
        (uword1==65) ||
        (uword1==69) ||
        (uword1==73) ||
        (uword1==76) ||
        (uword1==78) ||
        (uword1==79) ||
        (uword1==82) ||
        (uword1==83) ||
        (uword1==84) ||
        (uword1==85)
        )
    {
        total1++;
        printf("%i", total1);
    }
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