What is Conditional Statements in C++ in Hindi
C++ में Conditional Statements का Use कुछ Condition के आधार एक Program के flow को Control करने के लिए करते है।Types of Conditional Statements in C++ in Hindi
if Statement
C++ में "if" Statement, एक Fundamental control structure है{
block of code;
}
#include<iostream>
Enter the value of a:
1)ऊपर के Program में हमने दो Variables a और b को के लिए User से Input लिया है जो क्रमश: 5 और 7 है
का Code Execute हो जायेगा
if-else Statement
if - else statement, if statement की कमी को पूरा करता है क्योंकि if statement यदि Condition True है तब तो Block के Code Execute होंगे लेकिन Condition False होने पर कोई भी Statements Execute नही होगाif (condition)
{
Statement1;
}
else
{
Statement1;
}
#include <iostream>
1) ऊपर Program में num नामक, variable की Value, user से Input के रूप में लिया जाता है
Nested if Statement
C ++ में Nested if statement जटिल निर्णय का निर्माण करने के लिए एक शक्तिशाली tool हैएक if statement को दूसरे के अंदर nested करके आप क्रमिक रूप से कई Conditions का मूल्यांकन कर सकते है
if (condition1)
{
if or else statement
}
else
{
if or else statement
}
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout<<"Enter three numbers:"<<endl;
cin>>a>>b>>c;
//Using Nested if-else statements to find the largest number
if (a >= b) //Outer if block
{
if (a >= c) //Inner if block
{
cout<<"a is the largest number"<<endl;
}
else
{
cout<<"c is the largest number"<<endl;
}
}
else //else block start if Outer if block condition false
{
if (b >= c)
{
cout<<"b is the largest number"<<endl;
}
else
{
cout<<"c is the largest number"<<endl;
}
}
return 0;
}
Enter three numbers: 15 10 25
c is the largest number.
Explanation:
सबसे पहले User से तीन Numbers Input के रूप मे लिया जाएगा
Outer if block अगर True है तो निम्न कार्य होगा
1) पहले Outer if block के Condition को check किया जायेगा कि क्या a, b से बड़ा है यदि है तो Control Inner if block में जाकर पुन: a को c से Check किया जायेगा कि क्या a, c से बड़ा है
यदि यदि Condition False है अर्थात c बड़ा है तो c को Print किया जायेगा
Outer if block अगर False है तो निम्न कार्य होगा
1) यदि a, b से बड़ा नही है तो Program का Control else block में आ जायेगा
अब b को c से Check किया जायेगा अगर b बड़ा है, तो b Print होगा अन्यथा C Print होगा
Output Explanation:
Enter three numbers: 15 10 25
c is the largest number.
ऊपर a की Value 15, b की 10 और c की 25 है चूकि 25 जो की c की Value है बड़ी है इसलिए c को Largest number के रूप में Print किया जाएगा
else-if ladder
C++ मे "else-if ladder" एक Conditional Steps का क्रम है जब एक Condition पूरी नही होती, तो Program अगले Condition में चली जाती है और यह इसी तरह चलती रहती है जब तक कोई Condition पूरी न हो जाए या ladder के अन्त तक न पहुंच जाएif (condition1)
{
Statement 1
}
else if (condition2)
{
Statement 2
}
else if (condition3)
{
Statement 3
}
...
else {
Statement 4
}
#include <iostream>
{
1) सबसे पहले User से Score Input के रूप में लेते हैं
switch statement
C++ में एक switch statement एक शक्तिशाली Control structure हैswitch (expression)
case constant1:
statement 1
break;
case constant2:
statement 2
break;
.
.
.
default:
default statement 3
}
#include <iostream>
using namespace std;
int main()
{
char yourGrade;
cout<<"Enter your grade:"<<endl;
cin>>yourGrade;
switch (yourGrade) { case 'A': cout<<"Excellent"; break; case 'B': cout<<"Good"; break; case 'C': cout<<"Average"; break; default: cout<<"Improve your grade"; } return 0; }
Explanation
ऊपर Program में switch statement एक Variable(yourGrade) के value को जो कि एक Character है, को मूल्यांकित करता है और उस Value के आधार पर उचित Case को Execute करता है
Related Posts
> C++ क्या है? उसके इतिहास, गुण, उपयोग, फायदे और नुकसान
> Basic structure of C++ Program
> C++ में Tokens क्या है? और उसके प्रकार
> C++ Variables क्या है?, उसके प्रकार, उसे कैसे Declare, Define करते हैं
> C++ में Constants क्या है? उसके प्रकारों की संपूर्ण जानकारी
> C++ में Basic Input और Output (cin,cout,cerr) की जानकारी
> Data type in C++ की संपूर्ण जानकारी
> C+ में Operators और उसके प्रकार जानें Practical सहित
> C++ में Looping statements और उसके प्रकार Practical सहित
> C++ में Jump Statements और उसके प्रकारों की संपूर्ण जानकारी Practical सहित
> C++ में Array क्या है? और उसके प्रकारों की जानकारी Practical सहित
> C++ में Function क्या है उसके प्रकार, उपयोग प्रोग्राम सहित
> C++ में Structure क्या है Practical सहित
> OOPs Concepts in C++ in Hindi- C++ में OOPs के बारे में
> Oops के फायदे और नुकसान की जानकारी
> C++ में Class और Object की सम्पूर्ण जनकारी
> C++ में Array of Objects क्या है?
> C++ में Pointers, Pointer to an objects, Pointer to an Array की संपूर्ण जानकारी हिंदी में।
> C++ में Passing objects क्या है
> C++ में Reference और Type Casting की संपूर्ण जानकारी
> C++ में Access specifier की संपूर्ण जानकारी
> C++ में Static Data Members और Member Functions के बारे में Practical सहित
> C++ में Memory allocation और Memory management operators (new और delete) Practical सहित
> Friend Function in C++ in Hindi
> Friend Class in C++ in Hindi Practical सहित
> Inline function in C++ in Hindi
> Function Overloading in C++ in Hindi Practical सहित
> Operator Overloading in C++ in Hindi Practical सहित
> C++ में Constructor क्या है और उसके प्रकारों की संपूर्ण जानकारी
> C++ में Destructor क्या है ?उसकी संपूर्ण जानकारी
> C++ मे Inheritance क्या है उसके प्रकारों को जानें प्रोग्राम सहित
> C++ में Polymorphism क्या है? और उसके प्रकारों को जानें
> C++ में Virtual function की संपूर्ण जानकारी
> C++ में File handling की संपूर्ण जानकारी
> C++ में Exception handling की संपूर्ण जानकारी
0 टिप्पणियाँ