Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!