Knowledge Point: For loop
structure; for (initial condition; cyclic condition; state change)
{EXECUTE statement under satisfied conditions}
print 20 times Hello;
for (int i=1;i<=20;i++)
{
if (i==6)
Break End the entire loop
Console.ritelinge ("Hello! ");
}
for (int i=1;i<=20;i++)
{
if (i==6)
Continue End this cycle
Console.ritelinge ("Hello! ");
}
Title: Enter a number, ask 1 to add to this number of the and;
Console.Write ("Please enter an integer");
int a = Int. Parse (Console.ReadLine ());
int sum = 0;
for (int i = 1; i <= A; i++)
{
sum = sum + i;
}
Console.WriteLine (sum);
Title: Enter a number to find factorial;
Console.Write ("Please enter an integer");
int a = Int. Parse (Console.ReadLine ());
int sum = 1;
for (int i = 1; i <= A; i++)
{
sum = sum * i;
}
Console.WriteLine (sum);
Title: Find out within 100 the number of 7-related and print;
for (int i = 1; i <=; i++)
{
if (i% 7 = = 0 | | i%10 = = 7 | | i/10 = = 7)
{
Console.Write (i+ "");
}
Title: A game, the first 2 requires 0 off the score is it itself, 21-30 is 10 minutes, 31 to 40 is 20 minutes, 41-49 is 30 points, the 50th level is 100 points;
Enter a level book to give a score.
Console.Write ("Please enter your clearance number a=");
int a = Int. Parse (Console.ReadLine ());
if (a<0| | A>50)
Console.WriteLine ("Your score was awarded as: 0" due to your random input);
Else
{
int sum = 0;
for (int i = 1; i <= A; i++)
{
if (i <=)
{
sum = Sum +i;
}
else if (i <=)
{
sum = sum + ten;
}
else if (i <=)
{
sum = sum +;
}
else if (i <)
{
sum = sum +;
}
Else
sum = sum + +;
}
Console.WriteLine ("Congratulations on your +sum+". ");
}
Title: Go to the steps, the first 49 knots each section of the score equals itself, the fifth festival begins each section 10 points, to seek the total score;
Console.Write ("Please tell me how many steps you have walked:");
int a = Int. Parse (Console.ReadLine ());
if (A < 0 | | a >)
Console.WriteLine ("Please do not enter it indiscriminately");
Else
{
int sum=0;
for (int i = 1; i <= A; i++)
{
if (i <)
{
sum + = i;
}
Else
{
sum + = ten;
}
}
Console.WriteLine ("Congratulations! The score you obtained is: "+sum);
}
Knowledge points: Nesting of for loops.
For the case, please 1! [Email protected]! ... +n!
Console.Write ("Please enter a positive integer");
int n = Int. Parse (Console.ReadLine ());
int sum=0;
for (int i=1;i<=n;i++)
{
int S=1;
for (int j=1;j<=i;j++)
{
s = S * j;
}
sum = sum + S;
}
Console.WriteLine (sum);
Title: Printing 99 multiplication table;
for (int i=1;i<10;i++)
{
for (int j = 1; J <= I; j + +)
{
Console.Write (j + "*" + i + "=" + i * j+ "\ t");
}
Console.WriteLine ();
}
Knowledge Points: Type of problem solving for a for loop, exhaustive and iterative;
To go through all the circumstances and use the IF statement to filter out the condition that satisfies the conditions;
Iterative, from the initial situation in accordance with the law to constantly solve the situation in the middle, the final derivation of the results;
A 150 of the shopping voucher to go to the supermarket to buy things, shampoo 15 yuan, soap 2 yuan, toothbrush 5 yuan;
Ask how many ways of shopping, each way to buy how much;
for (int i = 0,int x = 0; x <=)
{
for (int y = 0; y <=; y++)
{
for (int z = 0; z <=; z++)
{
if (x + 2 * y + z * 5 = =)
{
Console.WriteLine ("Total Buy shampoo" + x + "bottle, soap" + Y + "bottle, toothbrush" + z + "branch. ");
i + = 1;
}
}
}
}
Console.WriteLine ("A total of" +i+ "methods");
Paper can be stacked countless times, the thickness of the paper is 0.07 mm;
How many times can be more than 8848 meters;
double a=0.07/1000;
for (int i = 1;; i++)
{
a *= 2;
if (a >= 8848)
{
Console.WriteLine ("A total of" +i+ "Times");
Console.WriteLine ("The thickness after the overlay is" + a);
Break ;
}
}
or point: While loop structure: initial condition, while (restriction condition) {loop body, state change;}
Do while: initial condition, do {loop body, state change;} while (restriction)
Fourth day class