In C programming Im currently using printf3fi variable1 It g

In C programming

I\'m currently using printf(\"%.3fi\ \",variable1)

It gives me the right output for the second problem but the first problem I\'m having trouble.

It should print 3.2i instead it prints out 3.200i

I\'ve attached the screenshot

Thanks!

Enter the real component for the first number: Enter the imaginary component for the first number: Enter the real component for the second number: Enter the imaginary component for the second numbe The sum of the two complex number is -0.300 3.200 The difference of the two complex number is -6.500 7.600i Expected Enter the real component for the first number: 3.4 Enter the imaginary component for the first number:5.4 Enter the real component for the second number:3.1 Enter the imaginary component for the second number 2.2 The sum of the two complex number is -0.300 3.21 The difference of the two complex number is 50 4 7.6001 Enter the real component for the first number: Enter the imaginary component for the first number: Enter the real component for the second number Enter the imaginary component for the second number The sum of the two complex number is 14.200 2.4001 The difference of the two complex number is 4.000 8.000i Expected Enter the real component for the first number:9.1 Enter the imaginary component for the first number: Enter the real component for the second number:5.1 Enter the imaginary component for the second numbe 2.8 The sum of the two complex number is 14.200 2.4001 The difference of the two complex number is 4.000 0001

Solution

When using printf, a subsequence beginning with % is a format specifier that is replaced by the provided arguments (variable1, in this case).

The floating variable you are about to print will be rounded off to 3 decimal digits. If float variable is 3.1268, it becomes 3.127 and also 3.2 becomes 3.200

if you want to print 3.2i then use %1fi , it sets precision of at least 1 after the decimal.

I think this will help, have a nice day!!

In C programming I\'m currently using printf(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site