Search code examples
ccomplex-numbersspecifier

What does %di specifier do in C programming?


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

Solution

  • 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.