Pointer to function

Source: Internet
Author: User
Tags float max
# Include "stdio. H"
# Include "conio. H"
# Define M 8
Float max (float a [], int N);/** // * function declaration */
Void main ()
{
Clrscr ();
Float sumf, sump;
Float a [m] = {4.5,-3 };
Float (* p) (float a [], INT);/** // * defines the pointer to the function P */
P = max;/** // * function name (function entry address) assigned to pointer p */
Sump = (* p) (a, m);/** // * call a function using a pointer */
Sumf = max (a, m);/** // * use the function name to call the max () function */
Printf ("sump = %. 2f \ n", sump );
Printf ("sumf = %. 2f \ n", sumf );
}

Float max (float a [], int N)
{
Int K;
Float S;
S = A [0];
For (k = 0; k <n; k ++)
If (S <A [k]) S = A [k];
Return S;
}

Input two straight corner edges of a triangle in the main function to obtain the area and length of the triangle.

# Include "stdio. H"
# Include "conio. H"
# Include "math. H"
Float area (INT, INT );
Float length (INT, INT );
Float F (INT, Int, float (* p) (INT, INT ));
Void main ()
{
Clrscr ();
Int M, N;
Float S, L;
Float (* q) (INT, INT );
Scanf ("% d, % d", & M, & N );
Q = area;
S = f (m, n, q );
L = f (m, n, length );
Printf ("Area of the right triangle is %. 2f \ n", S );
Printf ("length of the hypotenuse is %. 2f \ n", L );
}

Float area (int A, int B)
{
Float Z;
Z = a * B/2;
Return Z;
}

Float length (int A, int B)
{
Float Z;
Z = SQRT (A * A + B * B );
Return Z;
}

Float F (int A, int B, float (* p) (INT, INT ))
{
Float y;
Y = (* p) (A, B );
Return y;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.