Using Range in the Case Values of Switch Statement | C Programming Video Tutorial

preview_player
Показать описание
In this c programming video tutorial you will learn to use Range in the switch statement case values with example.

using the Range feature starts at @6:31

GCC Compiler allows you to use this feature. usage of the range in the case values of the switch statement allows the programmer to execute a set of statements for a range of values.

Syntax for using the Range in switch case values
case LowerLimit ... upperlimit:

while using this feature you have to follow 2 rules.
LowerLimit can not be greater than the upperlimit.
none of the cases should contain overlapping values ( one value should not have matches in 2 or more cases ).

Subscribe for more tutorials

Social Media Links

#CProgramming #LearningLad #ComputerProgramming
Рекомендации по теме
Комментарии
Автор

1st of all thank u so much for explaining everything so slowly & clearly
as u ve asked for the simple program:
#include <stdio.h>
#include <stdlib.h>

int main()
{
char c= 'a';
switch(c){
case 'a' ... 'z':
printf("%c is lower case", c);
break;

case 'A' ... 'Z':
printf("%c is Upper case", c);
break;
default:
printf("default");
}
return 0;
}
changing the char value to M will execute 2nd case

mrgodspeed
Автор

THANK YOU SO MUCH SIR THIS HELPED A LOT I WAS STUCK IN A CODE THAT NEEDED RANGE USING SWITCH STATEMENTS

hampter-upqo
Автор

Code is as follow:


#include<stdio.h>
#include<conio.h>
int main(){
char x;
printf("pleaes enter the charcter.\n");
scanf("%c", &x);

switch(x){

case 'A' ... 'Z':
printf("the latter is upper case.\n");
break;

case 'a' ... 'z':
printf("the latter is lower case.\n");
break;

default:
printf("please, enter the correct charcter.\n");
}



getch();
return 0;
}

mohammedkhalid
Автор

In second case statement we can specify case 'a' ... 'z' :
print("%c between and z\n");
By modifying char value we get either one of the case

bhanuprakashreddy
Автор

sir you ar doing great.i have watched all your videos of c tutorial till now.Thank you sir

jeevankurian
Автор

Great job sir! U are a very hardworking person . Keep it up

RajMadhok
Автор

Thank you sir I have learned lots of concept from your video in simple way :) and still learning. I didn't know about range in switch case. Thanks

mayankyadav
Автор

#include <stdio.h>
int main()
{ char ch;
scanf("%c", &ch);
switch(ch)
{ case 'a' ... 'z':
printf("%c is lowercase");
break;
case 'A' ... 'Z':
printf("%c is uppercase");
break;
default:
printf("match not found");

}


return 0;
}

Hideto_
Автор

ohh my god wow what a solution hats off

Rapchik_is_online
Автор

thank you very much. I will use this in my arduino project

enesyuce
Автор

Hello, how about if the value for range is negative?

danjediaelcaranay
Автор

Sir when running on codeblocks it is compiling well but when I am running it it says do you want to build and if I say yes then it shows 2 errors saying multiple definition of main

rishirajagarwal
Автор

Pease can someone help? I am trying it in java with Eclipse Compiler, but it is not working. Can any one tell me how to compute switch stat in eclipse with range value please.

godslove
Автор

Sir. In switch use in calculator..
I want to continue the program with out using getch or do and while. Only
If and else . Can you help me..

jerahmaypasion
Автор

You should do a playlist for data structures

alisyed
Автор

Thanks alot.
This is what I think it's looks like please help me correct it if there is any mistake but the program ran on my system.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int main()
{
char c;
scanf(" %c", &c);

switch (c) {
case 'A' ... 'Z':
{
printf("\n %s is a capital letter", &c);
break;
}
case 'a' ... 'z':
{
printf("\n %s is a small letter", &c);
break;
}
}
getch();
return 0;
}

simbol
Автор

Sir, In the following program, it is not executed after the scanf portion i.e enter the no., After entering the no., BLANK ... PLZ help me out of this... I am a beginner...
#include<stdio.h>
#include<conio.h>
int main()
{
int x;
printf("Enter the number\n");
scanf("%d\n", &x);
switch( x ){
case 0 ... 12:
printf("YOU ARE A CHILD\n");
break;
case 13 ... 19:
printf("YOU ARE A TEENAGER\n");
break;
case 20 ... 40:
printf("YOU ARE AN ADULT\n");
break;
case 41 ... 100:
printf("YOU ARE A VETERAN");
break;
default:
printf("YOU ARE AN ALIEN");
}

getch();
return 0;

}

vivekdsouzaa