Case Control Structure – Theory and Programs [Learn to code]

What is Case Control Structure? Learn syntax for Case Control Structure, types of Case Control Structure and different programs on Case Control Structure.

  • 057. Write a program to accept a single value interger from user and print that integer in words in C language
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    	int n;
    	clrscr();
    	printf("Enter number...");
    	scanf("%1d",&n);  //%1d to scan single integer
    	switch(n)
    	{
    		case 0 : printf("Zero");break;
    		case 1 : printf("One");break;
    		case 2 : printf("Two");break;
    		case 3 : printf("Three");break;
    		case 4 : printf("Four");break;
    		case 5 : printf("Five");break;
    		case 6 : printf("Six");break;
    		case 7 : printf("Seven ");break;
    		case 8 : printf("Eigth ");break;
    		case 9 : printf("Nine ");break;
    	}
    	getch();
    }
  • 058. Write a program to accept a number from user and print that number in words but in reverse order in C language

    E.g. 153 -> THREE FIVE ONE

    #include<stdio.h>
    #include<conio.h>
    main()
    {
    	int n,rem;
    	clrscr();
    	printf("Enter number...");
    	scanf("%d",&n);
    	while(n>0)
    	{
    		rem=n%10;
    		switch(rem)
    		{
    		  case 0 : printf("Zero");break;
    		  case 1 : printf("One");break;
    		  case 2 : printf("Two");break;
    		  case 3 : printf("Three");break;
    		  case 4 : printf("Four");break;
    		  case 5 : printf("Five");break;
    		  case 6 : printf("Six");break;
                      case 7 : printf("Seven");break;
    		  case 8 : printf("Eigth");break;
    		  case 9 : printf("Nine");break;
    		}
    		n=n/10;
     
    	}
    	getch();
    }
  • 059. Write a Program to accept two numbers and a operator (+, -, *, / from user and complete that particular operation only in C language
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    	int n,rem,a,b;
    	char op;
    	clrscr();
    	printf("Enter Operator(+,-,*,/)...");
    	scanf("%c",&op);
    	printf("Enter numbers...");
    	scanf("%d%d",&a,&b);
    	switch(op)
    	{
    	case '+' : printf("Result : %d ",a+b);break;
    	case '-' : printf("Result : %d ",a-b);break;
    	case '*' : printf("Result : %d ",a*b);break;
    	case '/' : printf("Result : %d ",a/b);break;
    	default  : printf("Invalid operator....");
    	}
    	getch();
    }

059. Write a Program to accept two numbers and a operator (+, -, *, / from user and complete that particular operation only in C language

#include<stdio.h>
#include<conio.h>
main()
{
	int n,rem,a,b;
	char op;
	clrscr();
	printf("Enter Operator(+,-,*,/)...");
	scanf("%c",&op);
	printf("Enter numbers...");
	scanf("%d%d",&a,&b);
	switch(op)
	{
	case '+' : printf("Result : %d ",a+b);break;
	case '-' : printf("Result : %d ",a-b);break;
	case '*' : printf("Result : %d ",a*b);break;
	case '/' : printf("Result : %d ",a/b);break;
	default  : printf("Invalid operator....");
	}
	getch();
}

058. Write a program to accept a number from user and print that number in words but in reverse order in C language

E.g. 153 -> THREE FIVE ONE

#include<stdio.h>
#include<conio.h>
main()
{
	int n,rem;
	clrscr();
	printf("Enter number...");
	scanf("%d",&n);
	while(n>0)
	{
		rem=n%10;
		switch(rem)
		{
		  case 0 : printf("Zero");break;
		  case 1 : printf("One");break;
		  case 2 : printf("Two");break;
		  case 3 : printf("Three");break;
		  case 4 : printf("Four");break;
		  case 5 : printf("Five");break;
		  case 6 : printf("Six");break;
                  case 7 : printf("Seven");break;
		  case 8 : printf("Eigth");break;
		  case 9 : printf("Nine");break;
		}
		n=n/10;
 
	}
	getch();
}

057. Write a program to accept a single value interger from user and print that integer in words in C language

#include<stdio.h>
#include<conio.h>
main()
{
	int n;
	clrscr();
	printf("Enter number...");
	scanf("%1d",&n);  //%1d to scan single integer
	switch(n)
	{
		case 0 : printf("Zero");break;
		case 1 : printf("One");break;
		case 2 : printf("Two");break;
		case 3 : printf("Three");break;
		case 4 : printf("Four");break;
		case 5 : printf("Five");break;
		case 6 : printf("Six");break;
		case 7 : printf("Seven ");break;
		case 8 : printf("Eigth ");break;
		case 9 : printf("Nine ");break;
	}
	getch();
}