please help...
In turbo c... write a program containing a function that will return the smallest of 3 floating point numbers.
before i write programs one should be in ur mind ,processors
like p4 or amd will not give exact precision
following is the code
#define max(a,b) a%26gt;b?a:b
main()
{
float a,b,c,d;
d=max(a,b);
printf("%d",(c%26gt;d?c:d));
}
Reply:smallest means the minimum, this is the right code:
#define min(a,b) a%26lt;b?a:b
main()
{
float a,b,c,d;
d=min(a,b);
printf("%d",(c%26lt;d?c:d));
}
Reply:The above two examples don't specifically include a function that returns the smallest of 3 floating point numbers.
#include %26lt;stdio.h%26gt;
double minof3(double a, double b, double c)
{
if (a %26lt; b %26amp;%26amp; a %26lt; c)
return a;
if (b %26lt; c)
return b;
return c;
}
int main()
{
double a=10, b = 7, c = 11;
printf("The minimum of %0.2f, %0.2f and %0.2f is %0.2f\n", a, b, c, minof3(a, b, c));
return 0;
}
violet
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment