The National Computer Grade examination two level course-C Language Programming _ 11th Chapter _ The further discussion to the function

Source: Internet
Author: User
Tags cos sin square root

Example 11.2

Tan x and cot x values are obtained by passing different function names to the trans function.

1#include <stdio.h>2#include <math.h>3 DoubleTranDouble(*) (Double),Double(*) (Double),Double);/*function Description Statement*/4 Main ()5 {6     Doubley, V;7v = -*3.1416/180.0;8y = Tran (sin, cos, v);/*First time Call*/9printf"Tan (=%10.6f\n)", y);Teny = tran (cos, sin, v);/*Second Call*/ Oneprintf"Cot (=%10.6f\n)", y); A } - DoubleTranDouble(*F1) (Double),Double(*F2) (Double),Doublex) - { the     return(*F1) (x)/(*F2) (x); -}

Example 11.3

Using recursive method to find n!

The n! can be expressed in the following mathematical relationships:

N!= 1 when N=0

n!= n * (n-1)! When n>0

1#include <stdio.h>2 intFacintN)3 {4     intT;5     if(n = =1|| n = =0)6     {7         return 1;8     }9     ElseTen     { Onet = N*FAC (N-1); A         returnT; -     } - } the Main () - { -     intm, y; -printf"Enter m:"); +scanf"%d", &m); -     if(M <0) +     { Aprintf"Input data Error!\n"); at     } -     Else -     { -y =FAC (m); -printf"\n%d!=%d\n", M, y); -     } in}

Example 11.4

The recursive algorithm is used to find the square root of a number a by using the iterative formula of the square root:

X1 = (x0 + a/x0)/2

1#include <stdio.h>2#include <math.h>3 DoubleMYSQRT (DoubleADoublex0)4 {5     DoubleX1;6X1 = (x0 + a/x0)/2.0;7     if(Fabs (x1-x0) >0.00001)8     {9         returnmysqrt (A, x1);Ten     } One     Else A     { -         returnX1; -     } the } - Main () - { -     DoubleA; +printf"Enter A:"); -scanf"%LF", &a); +printf"The sqrt of%f=%f\n", A, mysqrt (A,1.0)); A}

123

National Computer Grade Two tutorial-C language Programming _ 11th _ further discussion of functions

Related Article

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.