Calculator Program in C
इस विषय में, हम चर्चा करेंगे कि हम सी प्रोग्रामिंग भाषा में कैलकुलेटर प्रोग्राम कैसे लिखते हैं। कैलकुलेटर एक छोटा इलेक्ट्रॉनिक उपकरण है जिसका उपयोग विभिन्न अंकगणितीय संचालन जैसे जोड़, घटाव, गुणा, भाग, प्रतिशत आदि करने के लिए किया जाता है। यह हमारी गणना को आसान और तेज़ बनाता है। यह एक पोर्टेबल डिवाइस है जिसका उपयोग सरल गणितीय कार्य करने के लिए कहीं भी किया जा सकता है। हम कुछ स्थितियों में एक वैज्ञानिक या परिष्कृत कैलकुलेटर का उपयोग करते हैं, जहाँ हमें जटिल गणनाओं जैसे त्रिकोणमिति फ़ंक्शंस, एक्सपोनेंशियल ऑपरेटर्स, डिग्री, रेडियन, लॉग फ़ंक्शंस, हाइपरबोलिक फ़ंक्शंस आदि को हल करने की आवश्यकता होती है। आइए सी भाषा में कैलकुलेटर प्रोग्राम बनाने के विभिन्न तरीकों पर चर्चा करें।
Different ways to create a Calculator Program in C
सी भाषा में कैलकुलेटर प्रोग्राम लिखने के विभिन्न तरीके निम्नलिखित हैं।
- स्विच स्टेटमेंट का उपयोग करके C में कैलकुलेटर प्रोग्राम
- सी में कैलक्यूलेटर प्रोग्राम if else if कथन का उपयोग कर रहा है
- डू-वाइल लूप और स्विच स्टेटमेंट का उपयोग करते हुए
- सी में कैलकुलेटर प्रोग्राम फ़ंक्शन और स्विच स्टेटमेंट का उपयोग करके C में कैलकुलेटर प्रोग्राम
- C Program to Make a Simple Calculator Using switch...case
इस उदाहरण में, आप स्विच स्टेटमेंट का उपयोग करके C प्रोग्रामिंग में एक साधारण कैलकुलेटर बनाना सीखेंगे।यह प्रोग्राम उपयोगकर्ता से एक अंकगणितीय ऑपरेटर +, -, *, / और दो ऑपरेंड लेता है।
फिर, यह उपयोगकर्ता द्वारा दर्ज किए गए ऑपरेटर के आधार पर दो ऑपरेंड पर गणना करता है।
Algorithm
चरण 1: चर घोषित करें।
चरण 2: रनटाइम पर कोई ऑपरेटर दर्ज करें।
चरण 3: रनटाइम पर कोई भी दो पूर्णांक मान दर्ज करें।
चरण 4: ऑपरेटर चुनने के लिए स्विच केस लागू करें:
// मामला '+': परिणाम = अंक 1 + अंक 2; तोड़ना; मामला '-': परिणाम = संख्या 1 - संख्या 2; तोड़ना; मामला '*': परिणाम = संख्या 1 * अंक 2; तोड़ना; मामला '/': परिणाम = संख्या 1 / संख्या 2; तोड़ना; डिफ़ॉल्ट: प्रिंटफ (" अमान्य ऑपरेटर "); चरण 5: परिणाम प्रिंट करें।