5. C # basic arrangement (typical for statement exercises-nested with if ),
1,Basic use of the for Loop: After each landing, the ball is played again as the previous 4/5, and the height after the second bounce is calculated.
For (int I = 0; I <5; I ++) {high = high * 4/5;} Console. writeLine ("the height of the ball bounce for 5th times is: {0}", high );
Nested use of for loop and if statement:
2. You can guess the box with your computer and win the game in three games. (You have not considered the case of human error. The main reason is to practice the for loop first)
Int sum1 = 0; int sum2 = 0; string ren1; string dn1; for (int I = 0; I <3; I ++) {Random r = new Random (); int dn = r. next (3); // insert a random number from 0, 1, 2 and assign it to the Console. writeLine ("Enter your: 0-Scissors, 1-stone, 2-cloth"); int ren = int. parse (Console. readLine (); if (dn-ren =-1 | dn-ren = 2) sum1 ++; else sum2 ++; if (ren = 0) ren1 = "Scissors"; else if (ren = 1) ren1 = "Stone"; else ren1 = "cloth"; if (dn = 0) dn1 = "Scissors "; else if (dn = 1) dn1 = "Stone"; else dn1 = "cloth"; Console. writeLine ("computer output {0}, you output {1}", dn1, ren1);} if (sum1> sum2) Console. writeLine ("you win"); else if (sum2> sum1) Console. writeLine ("Computer wins"); else Console. writeLine ("Draw ");
3. Sum of 7-related numbers within 100
int sum = 0;for (int i = 0; i < 100; i++){ if (i%7==0||i%10==7||i/10==7) sum = sum+i;}Console.WriteLine(sum);
4. Calculate the even and, odd and
Int ou = 0; int ji = 0; for (int I = 1; I <101; I ++) {if (I % 2 = 0) ou = ou + I; else ji = ji + I;} Console. writeLine ("even and {0}, odd and {1}", ou, ji );