Answers for "switch c"

C
33

switch c

switch (n)
{
    case 1: // code to be executed if n = 1;
        break;
    case 2: // code to be executed if n = 2;
        break;
    default: // code to be executed if n doesn't match any cases
}
Posted by: Guest on March-12-2020
15

switch statement in c

#include <stdio.h>

int main(void)
{
  	int a = 0;
  
    switch(a)
    {
       case 1 :
          statement("a = 1");
          break;

       case 2 :
          printf("a = 2");
          break;

       default :
       	  printf("a is neither 1 or 2");
	      break;
    }
}
Posted by: Guest on September-07-2020
11

switch case c

switch (expression) {
    case constant1:
      // statements
      break;

    case constant2:
      // statements
      break;

    default:
      // default statements
}
Posted by: Guest on February-20-2020
5

c switch

int i;

switch (i){
  case 1:
    	//The Proccess you want to be executed
    	break;
  case 2:
    	//The Proccess you want to be executed
   		break;
  default:
    	break;
}
Posted by: Guest on January-12-2021
6

switch case in c

// example of switch case statement
#include <stdio.h>

int main() {
    char operator;
    double n1, n2;

    printf("Enter an operator (+, -, *, /): ");
    scanf("%c", &operator);
    printf("Enter two operands: ");
    scanf("%lf %lf",&n1, &n2);

    switch(operator)
    {
        case '+':
            printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
            break;

        case '-':
            printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
            break;

        case '*':
            printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
            break;

        case '/':
            printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
            break;

        // operator doesn't match any case constant +, -, *, /
        default:
            printf("Error! operator is not correct");
    }

    return 0;
}
Posted by: Guest on June-07-2020
1

switch c

int main(){
	int n;
    printf("choose one of those numbers (1, 2, 3)";
    fflush("stdin");
    switch(n){
    
   	case 1:
    
    	//do something if n = 1
    	break;
    
    case 2:
    
    	//do something if n = 2
    	break;
    case 3:
    	//do something if n = 3
    	break;
        
	default:
    
    	printf("holy moly you suck");
	}
    return 0;
Posted by: Guest on May-04-2021

Code answers related to "C"

Browse Popular Code Answers by Language