a1+ ib1 और a2 + ib2 के रूप में दो सम्मिश्र संख्याएँ दी गई हैं, कार्य इन दो सम्मिश्र संख्याओं को जोड़ना है।
सम्मिश्र संख्याएँ वे संख्याएँ होती हैं जिन्हें "a+ib" के रूप में व्यक्त किया जा सकता है जहाँ "a" और "b" वास्तविक संख्याएँ हैं और i एक काल्पनिक संख्या है जो व्यंजक 2 =-1 का हल है क्योंकि नहीं वास्तविक संख्या समीकरण को संतुष्ट करती है इसलिए इसे काल्पनिक संख्या कहते हैं।
इनपुट
a1 = 3, b1 = 8 a2 = 5, b2 = 2
आउटपुट
Complex number 1: 3 + i8 Complex number 2: 5 + i2 Sum of the complex numbers: 8 + i10
स्पष्टीकरण
(3+i8) + (5+i2) = (3+5) + i(8+2) = 8 + i10
इनपुट
a1 = 5, b1 = 3 a2 = 2, b2 = 2
आउटपुट
Complex number 1: 5 + i3 Complex number 2: 2 + i2 Sum of the complex numbers: 7 + i5
स्पष्टीकरण
(5+i3) + (2+i2) = (5+2) + i(3+2) = 7 + i5
समस्या को हल करने के लिए नीचे उपयोग किया गया दृष्टिकोण इस प्रकार है
-
वास्तविक और काल्पनिक संख्याओं को संग्रहीत करने के लिए एक संरचना घोषित करें।
-
इनपुट लें और सभी सम्मिश्र संख्याओं की वास्तविक संख्याएँ और काल्पनिक संख्याएँ जोड़ें।
एल्गोरिदम
Start
Decalre a struct complexnum with following elements
1. real
2. img
In function complexnum sumcomplex(complexnum a, complexnum b)
Step 1→ Declare a signature struct complexnum c
Step 2→ Set c.real as a.real + b.real
Step 3→ Set c.img as a.img + b.img
Step 4→ Return c
In function int main()
Step 1→ Declare and initialize complexnum a = {1, 2} and b = {4, 5}
Step 2→ Declare and set complexnum c as sumcomplex(a, b)
Step 3→ Print the first complex number
Step 4→ Print the second complex number
Step 5→ Print the sum of both in c.real, c.img
Stop में प्रिंट करें। उदाहरण
#include <stdio.h>
//structure for storing the real and imaginery
//values of complex number
struct complexnum{
int real, img;
};
complexnum sumcomplex(complexnum a, complexnum b){
struct complexnum c;
//Adding up two complex numbers
c.real = a.real + b.real;
c.img = a.img + b.img;
return c;
}
int main(){
struct complexnum a = {1, 2};
struct complexnum b = {4, 5};
struct complexnum c = sumcomplex(a, b);
printf("Complex number 1: %d + i%d\n", a.real, a.img);
printf("Complex number 2: %d + i%d\n", b.real, b.img);
printf("Sum of the complex numbers: %d + i%d\n", c.real, c.img);
return 0;
} आउटपुट
यदि उपरोक्त कोड चलाया जाता है तो यह निम्न आउटपुट उत्पन्न करेगा -
Complex number 1: 1 + i2 Complex number 2: 4 + i5 Sum of the complex numbers: 5 + i7