JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Decision Making Tools : Swich or goto statement in hindi in c language स्विच और गोटू स्टेटमेंट

स्विच और गोटू स्टेटमेंट Decision Making Tools : Swich or goto statement in hindi in c language :-
जैसे-जैसे conditions बढती है वैसे वैसे if else structure की complexity बढती जाती है | और प्रोग्राम को पढना और समझना मुश्किल हो जाता है लेकिनं C language दो statements की facility दी है :-
Switch Statement :
Switch statement एक multiway decision statement है |switch statement किसी expression को check करता है उस expression के मिलने वाले constant और integer के अनुसार blocks (Group of statements) execute हो जाता है |इस struture निन्म है :-
switch(expression)
{
case value 1:
      block 1;
      break;
case value 2:
      block 2;
      break;
……………….
……………….
……………….
case value n:
   block n;
   break;
}
Statement ;
इस syntax मे expression का आउटपुट constant और integer और character हो सकता है | ये आउटपुट value 1,value 2,……………………..value n होता  है |
Break statement उस switch statement मे block को terminate करने के लिए किया जाता है |इसके अलावा default block होता है जो  expression के आउटपुट को किसी भी case value से ना मिलने पर execute होता है|
उदहारण के लिए :
#include <conio.h>
void main ()
{
int a,b,c;
float Avg;
printf(“Enter your four subject martks = /n”)  ;
scanf(“%d %d %d %d”,&a,&b,&c,&d) ;
Avg = (a+b+c+d)/4;
switch((int)Avg/10)
{
case 10:
case 9:
case 8:
printf(“Honours”);
break;
case 7:
case 6:
printf(“First division”);
break;
case 5:
printf(“Second division”);
case 4:
case 3:
printf(“Third division”);
default:
printf(“Fail”);
}
}
इस उदाहरण मे चार subject के मार्क्स के averge को Avg मे assign हो जाता है जिसका data type float है | switch मे यूज़ करने के लिए Avg को data type को type casting से integer मे convert किया जाता है |
अगर Avg की value 10,9,8 है तब  Honours होगा |
जब Avg की value 7,6 होगी तब First division होगा |
जब Avg की value 5 होगी तब Second division होगा |
जब Avg की value 3,4 होगी तब Third division होगा |
default value मे Fail message आयेगे |
आउटपुट होगा :-
Enter your four subject marks =
85 66 67 89
First division
Switch statement के rule:
1. switch expression का आउटपुट integral हो चाहिए|
2.case lable unique होने चाहिए|
3.switch statement मे केवल एक default block हो सकता है |
4.case label ऑप्शनल है |

go to Statement :

सब किसी प्रोग्राम मे किसी block (Group of Statements) को बार बार  repeat करना होता है  tab इस statement का use हो जाता है |
goto statement मे name  की जरुरत होती है name उस block का नाम है जिसे प्रोग्रामर को repeat करना है |ये statement दो प्रकार से इस्तेमाल करता है |
1.BACKWARD JUMP Looping:
अगर EXECUTION BLOCK goto statement से पहले है और condition check होने के बाद EXECUTION BLOCK repeat होता है | इसका STRUCTURE है :-
read  name :
  block statements;
  ………………………;
  ………………………;
if (condition)
goto name ;
2.FORWARD JUMP looping :
जब EXECUTION BLOCK goto statement के बाद होता है और condition पहले check होती और बाद मे EXECUTION BLOCK execute होता है |
if (condition)
goto name;
statement  ;
……………..;
read  name :
  block statements;
  ………………………;
  ………………………;
उदहारण के लिए :
इस उदहारण मे हम tabel print करायेगे|
#include <conio.h>
void main ()
{
int a=0;
int table ;
printf(“Enter your number”);
scanf(“%d”,&table)
int mul;
read code:
a=a+1;
mul=a*table;
printf(“a*table=%d”,mul);
if(a<=10)
goto code;
}
इस उदहारण मे backward jump मे होता है |जिसमे प्रोग्रामर द्वारा code block statements तब तक repeat होता है जब तक a की value 0 से 10 तक नहीं हो जाती है |
आउटपुट होगा :-
Enter your number 2
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20
Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now