Posts

Showing posts from November, 2026

C++ Program for Swapping Two Numbers Without Using a Third Variable (तीसरे Variable का उपयोग किए बिना दो संख्याओं की अदला-बदली करने का C++ प्रोग्राम)

Swapping means exchanging the values of two variables. In this C++ program, we swap two numbers without using a third variable. We use arithmetic operators ( + and - ) to exchange their values. स्वैपिंग (Swapping) का अर्थ दो Variables के मानों को आपस में बदलना है। इस C++ प्रोग्राम में तीसरे Variable का उपयोग किए बिना Arithmetic Operators ( + और - ) की सहायता से दो संख्याओं के मान बदले जाते हैं। C++ Program #include <iostream> using namespace std; int main() { float a, b; cout << "Enter Two Numbers: "; cin >> a >> b; cout << "\nBefore Swapping:" << endl; cout << "a = " << a << " and b = " << b << endl; a = a + b; b = a - b; a = a - b; cout << "\nAfter Swapping:" << endl; cout << "a = " << a << " and b = " << b << endl; return 0; } Sample Output (उदाहरण आउटपुट) Enter ...

C++ Program for Swapping Two Numbers Using a Third Variable (तीसरे Variable की सहायता से दो संख्याओं की अदला-बदली करने का C++ प्रोग्राम)

Swapping means exchanging the values of two variables. In this C++ program, we use a third variable to swap the values of two numbers. स्वैपिंग (Swapping) का अर्थ दो Variables के मानों को आपस में बदलना है। इस C++ प्रोग्राम में दो संख्याओं के मानों को बदलने के लिए तीसरे Variable का उपयोग किया गया है। C++ Program #include <iostream> using namespace std; int main() { float a, b, c; cout << "Enter Two Numbers: "; cin >> a >> b; cout << "\nBefore Swapping:" << endl; cout << "a = " << a << " and b = " << b << endl; c = a; a = b; b = c; cout << "\nAfter Swapping:" << endl; cout << "a = " << a << " and b = " << b << endl; return 0; } Sample Output (उदाहरण आउटपुट) Enter Two Numbers: 10 20 Before Swapping: a = 10 and b = 20 After Swapping: a = 20 and b = 10 Explanation of the P...

C++ Program for Parking Charges of Two-Wheelers, Four-Wheelers and Heavy Vehicles (दोपहिया, चार पहिया और भारी वाहनों का पार्किंग शुल्क ज्ञात करने का C++ प्रोग्राम)

A parking management system is used to calculate parking charges according to the type of vehicle and the total parking duration. In this C++ program, we use a class named Parking to calculate the parking charges for three types of vehicles: Two-Wheelers – Bike or Scooter Four-Wheelers – Car or Loading Vehicle Heavy Vehicles – Bus or Truck The program accepts the vehicle type, vehicle number, entry time, exit time and parking days. It then calculates the total parking duration and displays the parking receipt. पार्किंग प्रबंधन प्रणाली का उपयोग वाहन के प्रकार और पार्किंग की कुल अवधि के आधार पर शुल्क ज्ञात करने के लिए किया जाता है। इस C++ प्रोग्राम में Parking नाम की Class बनाई गई है, जो तीन प्रकार के वाहनों का पार्किंग शुल्क ज्ञात करती है। Parking Charges (पार्किंग शुल्क) Vehicle Type Vehicle Category First 24 Hours Additional Hours 1 Bike / Scooter ₹10 per hour ₹1 per hour 2 Car / Loading Vehicle ₹20 per hour ₹5 per hour 3 Bus / Truck ₹50 per hour ₹10 per hour C++ Program #include ...

C++ Program to Check Whether a Given Year is a Leap Year or Not (दिया गया वर्ष Leap Year है या नहीं, जाँचने का C++ प्रोग्राम)

A Leap Year is a year that contains 366 days instead of the usual 365 days. February has 29 days in a leap year instead of 28 days. A year is a leap year if It is completely divisible by 400, or It is divisible by 4 but not divisible by 100. Leap Year वह वर्ष होता है जिसमें सामान्य 365 दिनों के स्थान पर 366 दिन होते हैं। सामान्य वर्ष में February के 28 दिन होते हैं, जबकि Leap Year में February के 29 दिन होते हैं। किसी वर्ष को Leap Year माना जाता है यदि वह 400 से पूर्णतः विभाजित हो, अथवा 4 से विभाजित हो लेकिन 100 से विभाजित न हो। C++ Program #include <iostream> using namespace std; int main() { int year; cout << "Enter a year: "; cin >> year; if (year % 400 == 0) { cout << year << " is a leap year." << endl; } else { if (year % 100 == 0) { cout << year << " is not a leap year." << endl; } else { if (y...

C++ Program to Check Whether an Alphabet is Vowel or Consonant Using switch-case (Vowel या Consonant की जाँच)

This C++ program checks whether a given alphabet is a vowel or a consonant using the if statement and switch-case statement. यह C++ प्रोग्राम if तथा switch-case स्टेटमेंट की सहायता से दिए गए alphabet के vowel या consonant होने की जाँच करता है। Program: #include <iostream> using namespace std; int main() { char ch; cout << "Enter an alphabet: "; cin >> ch; // Check whether the input is an alphabet if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { switch (ch) { case 'A': case 'a': case 'E': case 'e': case 'I': case 'i': case 'O': case 'o': case 'U': case 'u': cout << ch << " is Vowel" << endl; ...

C++ Program to Calculate Percentage and Display Division Using if-else (प्रतिशत एवं डिवीजन ज्ञात करना)

This C++ program accepts the percentage of a student and displays the division based on the percentage obtained using nested if-else statements. यह C++ प्रोग्राम विद्यार्थी का प्रतिशत input करता है तथा nested if-else statements की सहायता से प्राप्त प्रतिशत के आधार पर उसकी division प्रदर्शित करता है। Program: #include <iostream> using namespace std; int main() { float per; cout << "Enter Percentage of student: "; cin >> per; if (per >= 60) { cout << "I Division " << per << "%" << endl; } else { if (per >= 45) { cout << "II Division " << per << "%" << endl; } else { if (per >= 33) { cout << "III Division " << per << "%" << endl; } else { c...

C++ Program to Find Greatest Among Three Numbers Using if-else (तीन संख्याओं में सबसे बड़ी संख्या ज्ञात करना)

In this program, we use nested if-else statements to find the greatest or largest among three numbers. इस प्रोग्राम में nested if-else statements की सहायता से तीन संख्याओं में से सबसे बड़ी संख्या ज्ञात की जाती है। Program: #include <iostream> using namespace std; int main() { float a, b, c; cout << "Enter Three Numbers: "; cin >> a >> b >> c; if (a > b) { if (a > c) { cout << a << " is greatest" << endl; } else { cout << c << " is greatest" << endl; } } else { if (b > c) { cout << b << " is greatest" << endl; } else { cout << c << " is greatest" << endl; } } return 0; } Output 1: Enter Three Numbers: 10 25 15 25 is greatest Output 2: Enter T...

switch-case Statement in C++ (C++ में switch-case स्टेटमेंट)

A switch-case statement allows the value of a variable or expression to be compared with multiple constant values. When a matching case is found, the statements associated with that case are executed. The expression used in a switch statement must have an integral or enumeration type. In common introductory C++ examples, int and char values are used. C++ में switch-case स्टेटमेंट की सहायता से किसी variable या expression की value को कई constant values के साथ compare किया जा सकता है। जब कोई matching case मिल जाता है, तो उस case के statements execute किए जाते हैं। switch expression का type integral या enumeration type होना चाहिए। सामान्य उदाहरणों में int तथा char का प्रयोग किया जाता है। Syntax (सिंटैक्स) switch (expression) { case constant1: statements; break; case constant2: statements; break; case constant3: statements; break; // Other cases default: statements; } Explanation of switch-case (switch-case ...

Ternary Operator in C++ (C++ में टर्नरी ऑपरेटर)

The Ternary Operator is a special operator available in C and C++. It is also known as the Conditional Operator . It is a shorthand way of writing a simple if-else statement. The ternary operator is represented by ?: . First, the condition is evaluated. If the condition is true, the expression after ? is selected. If the condition is false, the expression after : is selected. Ternary Operator C और C++ में उपलब्ध एक विशेष ऑपरेटर है। इसे Conditional Operator भी कहा जाता है। इसका प्रयोग simple if-else स्टेटमेंट को संक्षिप्त रूप में लिखने के लिए किया जाता है। Ternary Operator को ?: से दर्शाया जाता है। इसमें सबसे पहले condition check की जाती है। यदि condition सत्य होती है, तो ? के बाद वाला expression select होता है। यदि condition असत्य होती है, तो : के बाद वाला expression select होता है। Syntax (सिंटैक्स) (condition) ? expression_if_true : expression_if_false; Example (उदाहरण) int x = 10, y = 20; (x < y) ? cout << y << " is greater" : cout << x...

Nested if-else Statement in C++ (C++ में Nested if-else स्टेटमेंट)

We can define one if-else statement inside another if or else block. This type of statement is called a Nested if-else Statement . It allows the programmer to check multiple test conditions and execute different statements according to the conditions. हम एक if-else स्टेटमेंट के अंदर दूसरे if-else स्टेटमेंट को define कर सकते हैं। इस प्रकार के स्टेटमेंट को Nested if-else Statement कहा जाता है। यह प्रोग्रामर को दो या दो से अधिक conditions को check करने तथा उनके अनुसार अलग-अलग statements execute करने की सुविधा प्रदान करता है। Types of Nested if-else Statements (Nested if-else के प्रकार) Nested if-else statements can be written in different forms. Some common structures are given below. Nested if-else statements को अलग-अलग structures में लिखा जा सकता है। कुछ सामान्य structures निम्नलिखित हैं। 1. Nested if-else inside an if block if (condition1) { if (condition2) { statements; } else { statements; } statements; } else { statements; } 2. ...

if-else Statement in C++ (C++ में if-else स्टेटमेंट)

The if-else statement is used to check a test condition and execute one of two alternative blocks of statements. If the test condition is true, the statements inside the if block are executed. Otherwise, the statements inside the else block are executed. if-else स्टेटमेंट का प्रयोग किसी टेस्ट कंडीशन को जाँचने तथा दो विकल्पों में से एक विकल्प के स्टेटमेंट रन करने के लिए किया जाता है। यदि टेस्ट कंडीशन सत्य (True) होती है, तो if ब्लॉक के स्टेटमेंट रन किए जाते हैं। अन्यथा else ब्लॉक के स्टेटमेंट रन किए जाते हैं। Syntax (सिंटैक्स) 1. Single Statement if (condition) statement; else statement; 2. Multiple Statements (if-else Block) if (condition) { statements; ... } else { statements; ... } Example (उदाहरण) C++ program to find whether a given integer is even or odd. एक C++ प्रोग्राम लिखिए जो यह पता करे कि दिया गया integer even number है या odd number। Program: #include <iostream> using namespace std; int main() { int n; cout << "Enter an ...

if Statement in C++ (C++ में if स्टेटमेंट)

The if statement is used to evaluate a test condition. If the condition is true, the statement or statements inside the if block are executed. Otherwise, the program control moves to the next statement after the if block. C++ में if स्टेटमेंट का प्रयोग किसी टेस्ट कंडीशन को जाँचने के लिए किया जाता है। यदि टेस्ट कंडीशन सत्य (True) होती है, तो if ब्लॉक के स्टेटमेंट रन किए जाते हैं। अन्यथा प्रोग्राम कंट्रोल if ब्लॉक के बाद आने वाले अगले स्टेटमेंट पर पहुँच जाता है। Syntax (सिंटैक्स) 1. Single Statement if (condition) statement; 2. Multiple Statements (if Block) if (condition) { statements; statements; ... } Here, the statements inside the block are executed only when the condition is true. यहाँ ब्लॉक के अंदर दिए गए स्टेटमेंट तभी रन किए जाते हैं जब कंडीशन सत्य होती है। Example: C++ program to print First Division when the percentage of a student is 60% or more. एक C++ प्रोग्राम लिखिए जो विद्यार्थी का प्रतिशत 60% या उससे अधिक होने पर First Division प्रदर्शित करे। Program...

Type Casting in C++ (सी++ में टाइप कास्टिंग)

To convert a value of one data type into another data type is known as type casting or type conversion. C++ allows constants and variables of different data types to be used in an expression. During evaluation, the compiler may automatically convert values to appropriate types according to the conversion rules. एक डेटा टाइप के मान को किसी दूसरे डेटा टाइप में परिवर्तित करना Type Casting या Type Conversion कहलाता है। C++ में एक एक्सप्रेशन में विभिन्न डेटा टाइप के वेरिएबल और कॉन्स्टेंट का प्रयोग किया जा सकता है। एक्सप्रेशन का मूल्यांकन करते समय कम्पाइलर आवश्यकतानुसार डेटा टाइप को स्वतः परिवर्तित कर सकता है। There are two main types of type conversion: टाइप कन्वर्शन मुख्यतः दो प्रकार की होती है— Implicit Type Conversion (Automatic Type Conversion) Explicit Type Conversion (Manual Type Conversion) 1. Implicit Type Casting or Automatic Type Conversion (स्वतः टाइप कन्वर्शन) Implicit type conversion is performed automatically by the compiler when a value is converted to another compatible data...

Control Structure in C++ (C++ में कंट्रोल स्ट्रक्चर)

Image
A control structure is a statement or group of statements used to control the flow of execution in a program. It organizes instructions into logical units and determines the order in which they are executed. Control Structure एक ऐसा स्टेटमेंट या स्टेटमेंट्स का समूह है जिसका प्रयोग प्रोग्राम के Execution Flow को नियंत्रित करने के लिए किया जाता है। यह Instructions को Logical Units में व्यवस्थित करता है तथा यह निर्धारित करता है कि प्रोग्राम में स्टेटमेंट्स किस क्रम में Execute होंगे। Types of Control Structures (कंट्रोल स्ट्रक्चर के प्रकार) Control structures are classified into three main categories: कंट्रोल स्ट्रक्चर को मुख्यतः तीन प्रकारों में वर्गीकृत किया जाता है: Sequential Structure (सीक्वेंशियल स्ट्रक्चर) Selection Structure (सिलेक्शन स्ट्रक्चर) Iterative Structure (इटरेटिव स्ट्रक्चर) 1) Sequential Structure (सीक्वेंशियल स्ट्रक्चर) In a sequential structure, statements are executed one after another in the specified order. The program follows the sequence of instructions without s...