14, function output parameters, recursion

Source: Internet
Author: User

1, the function input parameter is directly available to the function, which is equivalent to a variable that has already been assigned. The output parameter is equivalent to defining a variable, assigning it in a function, and then calling the function to take the assigned value out of the function. Example 1: Enter the value of the a,b,c, judging is not a unary two-time equation:classProgram { Public stringFangcheng (DoubleADoubleBDoubleC out DoubleX1, out Doublex2) {            DoubleD = b * B-4AC; if(A = =0) {x1=-b/C; X2=-b/C; return "not a unary two-time equation ."; }            Else             {                     if(D <0) {x1= -1; X2= -1; return "No solution"; }                Else if(d = =0) {x1=-(b + math.sqrt (d))/(2*a); X2=-(B-math.sqrt (d))/(2*a); return "There are two equal real number roots."; }                Else{x1=-(b + D)/(2*a); X2=-(b-d)/(2*a); return "There are two unequal real-root"; }            }        }        Static voidMain (string[] args) {Program AAA=NewProgram (); Console.WriteLine ("Please enter the value of a:"); DoubleA =int.            Parse (Console.ReadLine ()); Console.WriteLine ("Please enter a value for B:"); Doubleb =int.            Parse (Console.ReadLine ()); Console.WriteLine ("Please enter a value for C:"); Doublec =int.            Parse (Console.ReadLine ()); Doublex1, x2; Console.WriteLine (Aaa.fangcheng (A,b,c, outX1, outx2)); Console.WriteLine ("x1="+ x1 +"\ n"+"x2="+x2);        Console.ReadLine (); }}2, recursive Example 2: (1The monkey Peaches, the day after picking half of the previous one, and the seventh day there is one, a total of a few? (2A man drove a flock of sheep and sold it to a village 1/3 Plus one, there are 2 in the seventh village, how many in total? (3A pair of young rabbits two months into a rabbit and gave birth to a pair of young rabbits, 9 months after the pair? classProgram { Public intTaozi (intDay ) {            if(Day = =7)            {                return 1; }            Else            {                intn =2* (Taozi (day +1) +1); returnN; }        }         Public intYangintcun) {            if(Cun = =7)            {                return 2; }            Else            {                intn =3* (Yang (cun +1) +1); returnN; }        }         Public intTuziintYue) {            if(Yue = =0)            {                return 1; }            Else            {                intn = Tuzi (yue-2)*2; returnN; }        }        Static voidMain (string[] args) {Program DD=NewProgram (); Console.WriteLine (Dd.taozi (1)); Console.WriteLine (Dd.yang (1)); Console.WriteLine (Dd.tuzi (9));        Console.ReadLine (); }}

14, function output parameters, recursion

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.