C Program to Swap Values of Two Variables Using a Third Variable तीसरे वेरिएबल की सहायता से दो वेरिएबल्स की वैल्यू स्वैप करने का प्रोग्राम

In C language, swapping means exchanging the values of two variables. A third variable is used temporarily to store one value so that the original value is not lost during the exchange.

सी लैंग्वेज में स्वैपिंग का अर्थ दो वेरिएबल्स की वैल्यू को आपस में बदलना होता है। इस प्रक्रिया में एक तीसरे वेरिएबल का प्रयोग किसी एक वैल्यू को अस्थायी रूप से स्टोर करने के लिए किया जाता है, ताकि वैल्यू बदलते समय मूल मान नष्ट न हो।

C Program

#include <stdio.h>
int main(void)
{
float a, b, c;
printf("Enter two values:\n");
scanf("%f %f", &a, &b);
printf("Before swapping: a = %.2f, b = %.2f\n", a, b);
c = a;
a = b;
b = c;
printf("After swapping: a = %.2f, b = %.2f\n", a, b);
return 0;
}

Output

Enter two values:
10 20
Before swapping: a = 10.00, b = 20.00
After swapping: a = 20.00, b = 10.00

Explanation व्याख्या:

Suppose a = 10 and b = 20. The following statements exchange their values:

मान लीजिए a = 10 तथा b = 20 हैं। निम्न स्टेटमेंट्स उनकी वैल्यू को आपस में बदलते हैं:

  1. c = a; — The value of a is stored in c.
    a की वैल्यू को c में स्टोर किया जाता है।

  2. a = b; — The value of b is assigned to a.
    b की वैल्यू को a में असाइन किया जाता है।

  3. b = c; — The original value of a, stored in c, is assigned to b.
    c में सुरक्षित a की मूल वैल्यू को b में असाइन किया जाता है।

Thus, the values of a and b are exchanged successfully.

इस प्रकार a तथा b की वैल्यू सफलतापूर्वक आपस में बदल जाती हैं।


Comments

Popular posts from this blog

C Language Topics in Hindi and English

Top High-Paying Tech Skills to Learn in 2025

Complete C Programming Syllabus | Advanced C Roadmap for Students