কম্পিউটার

সি ভাষার একটি ফাংশনে গঠন পাস করে দুটি জটিল সংখ্যা কীভাবে যোগ করবেন?


সি প্রোগ্রামিং ল্যাঙ্গুয়েজে দুটি জটিল সংখ্যা যোগ করার জন্য, ব্যবহারকারীকে দুটি জটিল সংখ্যাকে কাঠামোর সদস্য হিসাবে নিতে হবে এবং একটি ব্যবহারকারী-সংজ্ঞায়িত ফাংশন তৈরি করে সেই দুটি সংখ্যার উপর অতিরিক্ত কাজ করতে হবে।

অ্যালগরিদম

দুটি জটিল সংখ্যা যোগ করার জন্য নীচে দেওয়া একটি অ্যালগরিদম পড়ুন।

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);

উদাহরণ

একটি ফাংশন −

-এ গঠন পাস করে দুটি জটিল সংখ্যা যোগ করার জন্য নিম্নলিখিত C প্রোগ্রাম
#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. ওপেন অফিস ক্যালকে কিভাবে কলাম বা সারি সারি যোগ করবেন

  2. দুটি জটিল সংখ্যা যোগ করার জন্য জাভা প্রোগ্রাম

  3. কিভাবে আমরা পাইথনে জটিল সংখ্যায় পূর্ণসংখ্যার একটি স্ট্রিং আনপ্যাক করতে পারি?

  4. Windows 11 এ কিভাবে ভাষা যোগ করবেন