Home > Back-end >  Are learning c language, a don't understand the problems
Are learning c language, a don't understand the problems

Time:09-17

# include
Void main ()
{
Int a, b, c, Max, min,
The scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C);
Int sum=a + b + c, ji=a * b * c;
If (a> B)
{
Max=a;
Min=b;
}
The else
{
Max=b;
Min=a;
}
If (max> C)
Printf (" Max=% d \ n ", Max).
The else
Printf (" Max=% d \ n ", c);
If (minPrintf (" min=% d \ n ", min);
The else
Printf (" min=% d \ n ", c);
Printf (" sum=% d \ n ", sum);
printf (" average=% f \ n ", the sum/3.0);
printf (" \ n=% d ", ji);
}

CodePudding user response:

Printf (" average=% f \ n ", the sum/3.0);
With printf (" average=% f \ n ", the sum/3); Or printf (" average=% d \ n ", the sum/3.0);
Is wrong, this is why?

CodePudding user response:

Int the sum, sum/3 are integers, sum/3.0 is a floating point number,

CodePudding user response:

"/" to the operators in the use of the C inside

You with printf (" average=% f \ n ", the sum/3.0); Or printf (" average=% d \ n ", the sum/3); Look at the results

CodePudding user response:

# define _CRT_SECURE_NO_WARNINGS 1

# include
#include

Int main ()
{
Float a, b, c, Max, min, sum, ji.
Printf (" please enter the number three: ");
The scanf (" % f % f % f ", & amp; A, & amp; B, & amp; C);
Sum=a + b + c, ji=a * b * c;

If (a> B)
{
Max=a;
Min=b;
}
The else
{
Max=b;
Min=a;
}

If (max> C)
Printf (" Max=% 2 f \ n ", Max).
The else
Printf (" Max=% 2 f \ n ", c);

If (minPrintf (" min=% 2 f \ n ", min);
The else
Printf (" min=% 2 f \ n ", c);

Printf (" sum=% 2 f \ n ", sum);
Printf (" average=% 2 f \ n ", the sum/3.0);
Printf (" product=% 2 f \ n ", ji);
system("pause");
return 0;
}

CodePudding user response:

reference 1st floor qq_42383450 response:
printf (" average=% f \ n ", the sum/3.0);
With printf (" average=% f \ n ", the sum/3); Or printf (" average=% d \ n ", the sum/3.0);
Is wrong, this is why?


Sum is type int, the default is 3 int type, so the sum/3 is the result of the int type, should use the % d, the same sum should use % f/3.0, but it seems that the handling of different platforms, may be an error on the platform, not an error on another platform, but even if they don't complain to print the results is also wrong,

CodePudding user response:

# define _CRT_SECURE_NO_WARNINGS 1

# include
#include

Int main ()
{
Float a, b, c, Max, min, sum, ji.
Printf (" please enter the number three: ");
The scanf (" % f % f % f ", & amp; A, & amp; B, & amp; C);
Sum=a + b + c, ji=a * b * c;

If (a> B)
{
Max=a;
Min=b;
}
The else
{
Max=b;
Min=a;
}

If (max> C)
Printf (" Max=% 0.2 f \ n ", Max).
The else
Printf (" Max=% 0.2 f \ n ", c);

If (minPrintf (" min=% 0.2 f \ n ", min);
The else
Printf (" min=% 0.2 f \ n ", c);

Printf (" sum=% 0.2 f \ n ", sum);
Printf (" average=% 0.2 f \ n ", the sum/3.0);
Printf (" product=% 0.2 f \ n ", ji);
system("pause");
return 0;
}

CodePudding user response:

Printf (" average=% f \ n ", the sum/3.0);
Because to compute the sum/3.0, the compiler will convert the sum to floating point types, get is a float, format with the output of the % f,


With printf (" average=% f \ n ", the sum/3);
Sum is integer, 3 as an integer, calculations will only get the integer part and decimal part automatically ignore, get the integer, you use % f to output, some compiler complains, some of the integer to float again, according to that also displays only the plastic part,

Or printf (" average=% d \ n ", the sum/3.0);
Sum is integer, 3.0 is float, the value is a float, there is no problem, but you have to output format for % d, some of the compiler complains, some of the floating-point decimal Numbers to integers and then, according to that also displays only the plastic part,

CodePudding user response:

Is the sum of type int,/usage is dividend type which type is the result which type will be

CodePudding user response:

Know about the type of ascension,

CodePudding user response:

Know about the type of ascension,
  • Related