Answers for "C switch"

C
33

using switch case in 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
0

C switch

Switch(integer-expression)

{

Case c1:

       Code;

Case c2:                                                         //c1,c2,c3 are constants

       Code;                                                       //Code is any valid C code

Case c3:

      Code;

default:

      Code;

}
Posted by: Guest on August-21-2021

Code answers related to "C"

Browse Popular Code Answers by Language