Make complex number in C by R4R Team

Complex number:

Example :
2+3i
0+4i
-1-9i
These kind of number are known as complex number.
where 'i' is root -1.

How make complex number ?
We need two thing :
-real part of complex number number
-imaginary part of complex number

Syntax-
a+bi

Where 'a' is the real part.
and 'b' is the imaginary part.

To create a complex number type structure, there are many logic may be possible, one of the way to create a complex number is :

program-

#include< stdio.h>
#include< string.h>
char complex(char r[10], char im[10])
{
char s[2]="+";
char i[2]="i";
s[1]='';
i[1]='';
strcat(r,s);
strcat(r,im);
strcat(r,i);
printf("Complex number is %s",r);
}
int main() {
char s1[10],s2[10];
printf("Enter real and imaginary part of the complex number\n");
scanf("%s%s",&s1,&s2);
complex(s1,s2);
}


output-

Enter real and imaginary part of the complex number
3
4
Complex number is 3+4i

-In this program, we take an input of real part and imaginary part of the complex number.
-Then pass in function 'complex()', which make complex number in the form of string and display on the screen.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!