आज हम conditional statement in hindi और conditional statement examples के बारे में जानेगे क्या होता हैconditional statement in hindi तो चलिए शुरु करते हैं:-
conditional statement in hindi:-
कभी - कभी ऐसे प्रोग्राम भी बनाए जाते हैं जिनमें आउटपुट दो प्रकार का होता है । यह आउटपुट किसी कंडीशन पर निर्भर करता है । कंडीशन के सही या : गलत होने पर आउटपुट अलग - अलग होते हैं । कंडीशन के सही होने पर सही वाले ब्लॉक का आउटपुट प्रदर्शित होगा , वही कंडीशन के गलत होने पर गलत वाले ब्लॉक का आउटपुट प्रदर्शित होगा ।
types of conditional statement:-
( i ) if statement in c in hindi
( ii ) Do case
(i) if statement in hindi: -
यह एक conditional statement है । इसके अन्तर्गत एक या एक से अधिक कंडीशन्स को लिखा जा सकता है । एक ही स्टेटमेन्ट में एक से अधिक कंडीशन्स के लिए लॉजिकल ऑपरेटर्स का प्रयोग किया जाता है । एक या दो प्रकार की कंडीशन्स के लिए if ....... else ....... end if का प्रयोग किया जाता है तथा अलग - अलग प्रकार की कंडीशन्स को nested if के द्वारा लिखा जा सकता है । nested if में if के अन्दर एक और if को लिखा जाता है । इसका Syntax हैं :
( a ) Syntax of if ....... else ........ endif
If <condition >
<Statements>
else
<Statements>
ended
If statment Example: Write a program to input age from the user and chck the user is eligible for voting or not.
Set Talk off
Clear
Store 0 to a
input "Enter your age " to a
if a >= 18
? "Eligible for voting"
else
? "Not eligible for voting"
endif
Set Talk on
Output-
Enter your age 17
Not eligible for voting
(b) Syntax of Nested if :- Method - 1
if< Condition 1>
if <Cordition 2>
<Statement>
Else
<Statement>
Endif
<Statement>
Else
<Statement>
Endif
Syntax of Nested if :- Method -2
if < Condition 1>
<Statement>
Else
if <Condition 2>
<Statement>
Else
<Statement>
Endif
Endif
If statement Example :- Accept Post from User and Print salary according to the following :-
(i) if Post is Manager Sal = 20,000/-
(ii) if Post is Executive Sal = 10,000/-
(iii) if Post is Trainee Sal = 7000/-
Set Talk off
Clear
store null to p
Accept "Enter Your Post " to P
if upper (P) = "MANAGER"
? "Salary is 20,000"
else
if upper (P) = "EXECUTIVE"
? "Salary is 10,000"
else
if upper (P) = "TRAINEE"
? "Salary is 7,000"
else
? "Wrong Post"
Endif
Endif
Endif
Set talk on
Output
Enter Your Post executive
Salary is 10000
Do case ....... end case:-
यह स्टेटमेन्ट Multiway स्टेटमेन्ट है । इसमें दिए गए इनपुट को प्रोग्राम में लिखे गए Case से मिलाया जाता है । कन्डीशन का मिलान जिस Case से हो जाता है । उस Case में लिखे स्टेटमेन्ट एक्जीक्यूट हो जाते हैं । इसका सिन्टैक्स इस प्रकार है:
Syntax:- Do Case
Case <Condition 1> <Satement>
Case <Condition 2> <Satement>
Case <Condition 3> <Satement>
Case n...
otherwise
<Statement>
End case
Example :- Write a program which takes number from 1 to 5 and print this number in a character format
Set talk off
Clear
Store 0 to num
Input "Enter a Number " to num
Do Case
Case num = 1
a = "one
Case num = 2
a = "two"
Case num = 3
a = "three"
Case num = 4
a = "four"
Case num = 5
a = "five"
Otherwise
? "Number is Not Between 1 to 5"
EndCase
? "Character format of your number is - ",a
Set talk on
Output :-
Enter a Number 3
Character format of your number is - three
टिप्पणियाँ
एक टिप्पणी भेजें