-2

%d specifier inside the printf function means that we're going to display the variable as a decimal integer and %f specifier would display it as a float number and so on. But what does %di specifier does ?

I found this specifier in this program(C program to add, subtract, multiply and divide Complex Numbers, complex arithmetic)

For example,

printf("Division of two complex numbers = %d %di",temp1/temp3,temp2/temp3);
R Sahu
  • 204,454
  • 14
  • 159
  • 270
makkBit
  • 373
  • 2
  • 14

4 Answers4

3

If temp/temp3 evaluates to 25 and temp2/temp3 evaluates to 15, the line

printf("Division of two complex numbers = %d %di",temp1/temp3,temp2/temp3);

will print

Division of two complex numbers = 25 15i

The i in the above format specifier prints the letter i. The %d parts print the numbers. The sole purpose of using i in the above format specifier is to print the real and imaginary parts of a complex number in a more user friendly way.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
2

There is no specifier "%di". So, it works as "%d" and after it you have a letter "i" (it is standard way to print imaginary part of complex values).

So when you have a line printf("Sum of two complex numbers = %d + %di",c.real,c.img); it works this way:

  • It prints "Sum of two complex numbers = ",
  • It prints value c.real,
  • It prints " + ",
  • It prints value c.img,
  • And it prints "i".
Ilya
  • 4,583
  • 4
  • 26
  • 51
2

There is no such thing as %di in C ! In fact %d has been used in the code for the integer! Since you are printing a complex number Such as

4 + 5i

You need to print an 'i immediately after you print 5 hence "%di" is used "%d" and i are seen seperately by the printf function!

Rahul Jha
  • 1,131
  • 1
  • 10
  • 25
0

There is no specifier "%di" in C. It just works normally as "%d" and after it you have a letter "i" printed. Example your output would look something like this:

int temp1=8;
int temp2=10;
int temp3=2;

printf("Division of two complex numbers = %d %di",temp1/temp3,temp2/temp3);

output:Division of two complex numbers = 4 5i

Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44