The sum of the FOR Loop statement, factorial, courtship, n times the height of the basketball jump

Source: Internet
Author: User

For Loop statement format:

 for (int1; /* Initial conditions */ ; /* Cycle Conditions */i++/* status change */)            {             // loop body, execute code ; (break; jump out of the loop body)             }

For the poor lifting method
Use the loop to go through all the possible situations, and then use the IF condition to filter out the results satisfying the requirements.

For iterative method

There is a certain regularity, from the initial situation according to the law constantly solve the intermediate situation, the final derivation of the results.

1 for several numbers and

            Console.WriteLine (" Please enter a number:");             int a = Convert.ToInt32 (Console.ReadLine ());             int 0 ;              for (int1; I <= A; i++)            {                = sum + i;            }            Console.WriteLine (" The sum of the numbers you enter is:" + sums);

2 finding factorial

Console.WriteLine ("Please enter a number:"); intA =Convert.ToInt32 (Console.ReadLine ()); intJC =1;  for(inti =1; I <= A; i++) {JC= JC *i; } Console.WriteLine ("The factorial of the number you enter is:"+JC); intCJ =1;  for(inti =1; I <=9; i++)            {                 for(intj =1; J <=9; J + +) {CJ= i *J; Console.Write (i+"*"+ j +"="+ CJ +"   ");            } Console.WriteLine (); }

3. Ask for an even number within 100

// ask for all even            numbers within 100  for (int0; i++)            {                if20)//% represents redundancy                {                    Console.WriteLine (i);                }            }

4. Find the height of the N-Times basketball Ball

 //the height of the blue ball bouncing upConsole.WriteLine ("Please enter the number of times:"); intA =Convert.ToInt32 (Console.ReadLine ()); DoubleGao =5;  for(inti =1; I <= A; i++)            {                if(I >5) {Gao=0; }                Else{Gao= GAO/2; }} Console.WriteLine ("Section"+ A +"the height of the second bounce is:"+ Gao. ToString ());

The sum of the FOR Loop statement, factorial, courtship, n times the height of the basketball jump

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.