4/15/2016

C Program To Add Two Complex Numbers Using Structures And Functions

Problem:- C Program To Add Two Complex Numbers By Passing Structure With Function Using Structure In C or C++ Program to Add Complex Numbers by Passing Structure or Adding two complex numbers using Structure in C or C Program To Add Two Complex Numbers By Passing Structure With Function or C program to Add two Complex Numbers using structures or C program to add two complex numbers or Write a C Program to add two complex numbers by passing structure or C Program to Add two Complex Numbers or Complex Number Using Struct or C++ program to add, subtract, multiply and divide two complex or Program to add two complex numbers.

What Is Structure

The structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. The structure is used to represent a record. Suppose you want to store a record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.

Defining a structure

struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.

Syntax :

struct structure_name

{
//Statements
};

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.

Solution:-

#include <stdio.h>
typedef struct complex
{
float real;
float imag;
}complex;

complex add(complex n1,complex n2);

int main()
{
complex n1,n2,temp;
printf("For 1st complex number \n");
printf("Enter real and imaginary respectively:\n");
scanf("%f%f",&n1.real,&n1.imag);
printf("\nFor 2nd complex number \n");
printf("Enter real and imaginary respectively:\n");
scanf("%f%f",&n2.real,&n2.imag);
temp=add(n1,n2);
printf("Sum=%.1f+%.1fi",temp.real,temp.imag);
return 0;
}

complex add(complex n1,complex n2)
{
complex temp;
temp.real=n1.real+n2.real;
temp.imag=n1.imag+n2.imag;
return(temp);
}

Output:-

No comments:

Post a Comment