Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> सी प्रोग्रामिंग

सी भाषा में किसी फ़ंक्शन में संरचना पास करके दो जटिल संख्याएं कैसे जोड़ें?

C प्रोग्रामिंग भाषा में दो सम्मिश्र संख्याओं को जोड़ने के लिए, उपयोगकर्ता को दो सम्मिश्र संख्याओं को संरचना सदस्यों के रूप में लेना होता है और उन दो संख्याओं पर एक उपयोगकर्ता-परिभाषित फ़ंक्शन बनाकर अतिरिक्त संचालन करना होता है।

एल्गोरिदम

दो सम्मिश्र संख्याओं को जोड़ने के लिए नीचे दिए गए एल्गोरिथम को देखें।

Step 1: Declare struct complex with data members.
Step 2: Declare name for structure and variables.
Step 3: Enter real and imaginary part for first complex number at run time.
Step 4: Enter real and imaginary part for second complex number at runtime
Step 5: Compute addition of number1 and number2 by calling function. Go to step 7.
Step 6: Print the result.
Step 7: Compute addition
  • Declare temp variable
  • temp.real = num1.real + num2.real;
  • temp.imag = num1.imag + num2.imag;
  • return (temp);

उदाहरण

फ़ंक्शन में संरचना पास करके दो जटिल संख्याओं को जोड़ने के लिए सी प्रोग्राम निम्नलिखित है -

#include <stdio.h>
typedef struct complex{
   float real;
   float imag;
} complex;
complex addition(complex num1, complex num2);
int main(){
   complex num1, num2, value;
   printf("entering real and imag parts of first complex no:\n ");
   scanf("%f %f", &num1.real, &num1.imag);
   printf("entering real and imag parts of second complex no:\n ");
   scanf("%f %f", &num2.real, &num2.imag);
   value= addition(num1, num2);
   printf("result = %.1f + %.1fi", value.real, value.imag);
   return 0;
}
complex addition(complex num1, complex num2){
   complex temp;
   temp.real = num1.real + num2.real;
   temp.imag = num1.imag + num2.imag;
   return (temp);
}

आउटपुट

जब उपरोक्त प्रोग्राम को निष्पादित किया जाता है, तो यह निम्नलिखित परिणाम उत्पन्न करता है -

entering real and imag parts of first complex no:
entering real and imag parts of second complex no:
result = 0.0 + 0.0i

  1. ओपन ऑफिस कैल्क में कॉलम या नंबर की पंक्तियों को कैसे जोड़ें

    क्या जानना है परिणाम प्रदर्शित करने के लिए सेल चुनें, फिर SUM (Σ .) ) दर्ज करें आस-पास के कॉलम या पंक्तियों को स्वचालित रूप से जोड़ने के लिए। यदि आवश्यक हो तो सीमा संशोधित करें। या FX श्रेणी  गणितीय . फ़ंक्शन . के अंतर्गत , SUM अगला जोड़ने के लिए सेल चुनें। एक और विकल्प है कि गणना करने के लिए ड

  1. हम पायथन में जटिल संख्याओं के पूर्णांकों की एक स्ट्रिंग को कैसे अनपैक कर सकते हैं?

    एक स्ट्रिंग में अल्पविराम द्वारा अलग किए गए दो पूर्णांक होते हैं। इसे पहले दो स्ट्रिंग्स की सूची में विभाजित किया जाता है जिनमें अंक होते हैं। >>> s="1,2".split(",") >>> s ['1', '2'] फिर दो वस्तुओं को पूर्णांक में बदल दिया जाता है और जटिल () फ़ं

  1. Windows 11 में भाषा कैसे जोड़ें

    Windows 11 में भाषा जोड़ें माइक्रोसॉफ्ट द्वारा की गई घोषणा के समय, विंडोज 11 उन लोगों के लिए एक मुफ्त अपग्रेड है, जिनके पास पहले से ही विंडोज 10 है। इस तरह, विंडोज 11 के साथ संगत सभी पीसी विंडोज 11 में अपग्रेड हो सकते हैं, जो केवल कुछ के द्वारा सीमित है। हार्डवेयर आवश्यकताएं जो विंडोज 11 की जरूरत ह