For loop problem, it s hard, what is called a for loop

Updated on Car 2024-05-23
16 answers
  1. Anonymous users2024-02-11

    for(i=0;i<2;i++)

    for(j=0;j<2;j++)

    for(k=0;k<2;k++) triple cycle.

    i=0j=0

    k=0 to print. k Loop:

    k = k + 1 = 1, k < 2;Print.

    k = k = 1 = 2, the k loop ends, and the j loop returns.

    i=0j = j + 1 = 1, j < 2 into k loops.

    k=0 to print. k Loop:

    k = k + 1 = 1, k < 2;Print.

    k = k = 1 = 2, the k loop ends, and the j loop returns.

    j = j + 1 = 2, j < 2 is not satisfied, j loop ends, i loop returns.

    i=i+1 = 1, i<2, into j loop.

    i=1j=0

    k=0 to print. k Loop:

    k = k + 1 = 1, k < 2;Do the printing. k Loop:

    k = k = 1 = 2, the k loop ends, and the j loop returns.

    i=1j = j + 1 = 1, j < 2 into k loops.

    k=0 to print. k Loop:

    k = k + 1 = 1, k < 2;Do the printing. k Loop:

    k = k = 1 = 2, the k loop ends, and the j loop returns.

    j = j + 1 = 2, j < 2 is not satisfied, j loop ends, i loop returns.

    i=i+1=2;If i < 2 is not satisfied, the i loop ends.

  2. Anonymous users2024-02-10

    Since the types you define are all ints, they will only be output if the operation satisfies the integer, so the first s is 1 instead of 0

  3. Anonymous users2024-02-09

    The first one is 0 and the program is fine.

    It is possible that the landlord's running window is not fully displayed.

    for(a=1;a<=100;a++)

    change to for(a=1; a<=2;a++) is fine, there is no need to loop so many times.

  4. Anonymous users2024-02-08

    The first output is s=0, it can't be s=1, but you can just track the running of the program.

  5. Anonymous users2024-02-07

    The for loop is a kind of loop statement in a programming language, and its expression is: for (single expression; conditional expressions; Loop body at the end). After the for loop executes the end loop body, the condition will be judged again, if the condition is still true, the above cycle will continue to be repeated, and when the condition is not true, the current for loop will be jumped.

    The three expressions inside the for parentheses are empty. In the for loop statement, the value of day is set to 1, and then the value of the conditional expression is judged according to the result of the conditional expression, and when the value of the conditional expression is true, the content in the loop is executed, that is, the printf function is called to display the value of day. After each unfinished loop, the last part of the parentheses in parentheses is executed.

    for loop statementIntroduction to Control Flow:

    init will be executed first, and only once. This step allows you to declare and initialize any circular control variables. You can also leave any statements here, as long as a semicolon appears.

    Next, the condition is determined. If true, the loop body is executed. If false, the loop body is not executed, and the control flow jumps to the next statement immediately following the for loop.

    After the body of the for loop is executed, the control flow jumps back to the increment statement above. This statement allows you to update the loop control variable. The statement can be left blank as long as a semicolon appears after the condition.

    The conditions are judged again. If true, the loop is executed, and the process is repeated over and over again (looping the body, then increasing the step value, and then rejudging the condition). When the condition becomes false, the for cycle is terminated.

  6. Anonymous users2024-02-06

    Enter continue to skip the current loop. break, to break out of the current loop.

    The for loop is open. Its general form is: for(; conditional expressions; Statement; Initialization is always an assignment statement that is used to assign an initial value to a loop control variable.

    The statement in the for loop can be a statement body, but it needs to be used""Enclose statements that participate in the loop.

    for loop"Parameter initialization expressions"、"conditional expressions; "with"Update the loop variable expression"are all optional, i.e. can be default, but";"It cannot be default. Initialization is omitted, indicating that no initial value is assigned to the loop control variable. If the conditional expression is omitted, it becomes an endless loop if nothing else is done.

    If the increment is omitted, the loop control variable is not operated, and the statement modifying the loop control variable can be added to the statement body. The three expressions of the for loop are all comma expressions, which means that each expression can be composed of several expressions, with the middle used", "spaced."

    For loops can be nested in multiple layers.

  7. Anonymous users2024-02-05

    “for(;;It's an endless loop.

    The for loop is a kind of open-bounded loop statement in programming languages, and the loop statement [1] consists of two parts: the loop body and the termination condition of the loop.

    The for loop in C is as follows.

    1.The shortest form of the statement is: for( ;

    2.The general form is: for (single expression; conditional expressions; end circulation body) intermediate circulation body;

    Among them, the expression can be omitted, but the semicolon cannot be omitted, because "; It can represent an empty statement, and after omitting it, the statement is reduced, that is, the statement format changes, and the compiler cannot recognize it and cannot compile it.

    for the first one in parentheses of the loop"; It is a single-time expression that does not participate in the loop, which can be used as an initial assignment statement for a variable, and is used to assign an initial value to the loop control variable. It can also be used to evaluate an expression that is not related to the for loop but precedes the loop section.

    both"; The conditional expression is a relational expression, which is the formal beginning of the loop, and when the conditional expression is true, the intermediate loop body is executed.

    The executed intermediate loop can be a single statement or multiple statements, and when the intermediate loop has only one statement, the curly brace {} can be omitted, and the end loop [2] is executed after the middle loop body is executed.

    After executing the end loop body, the condition will be judged again, and if the condition is still true, the above cycle will be repeated, and when the condition is not true, the current for loop will be jumped.

    For loop:for in Pascal Variable: = initial value to downto final value do,begin.

    Circulating body: end;

    Cyclic variables add 13 or subtract 1 each time from start to end (to is plus 1, downto is minus 1).

  8. Anonymous users2024-02-04

    #include

    int main()

    int a,b,c,abc,cba;

    for(a=0; a<=9;a++) exhaustive hundredsfor(b=0; b<=9;b++) exhaustive tens for(c=0; c<=9;c++) exhaustive single digit { abc=a*100+b*10+c; Composed of a three-digit CBA=C*100+B*10+A; Composition of the second three-digit if(abc+cba==1333) if the conditions are met printf("%d+%d=1333",abc,cba);Just output.

    return 0;

  9. Anonymous users2024-02-03

    Since you want to explain it in detail, I will start with the topic:

    The problem requires the function to be able to do 3 things:

    1. Calculate the average score; 2. Count the number of people with lower than average scores; 3. Save the scores below the average in another array.

    Let's break it down:

    First of all, to do this, you have to iterate over every element in the array, so loops are necessary, and for problems where the number of loops is known (the number of elements in the array is 9), we usually use a for loop.

    Second, when designing a program, we should follow the principle of using as few for loops as possible, and especially to avoid the nesting problem of for loops (which is obviously not needed). So, let's think about whether we can accomplish these 3 tasks with a single for loop. Obviously, no, because we can't get the average score (task 1) without calculating the overall score, and thus we can't compare which scores are lower than the average (tasks 2, 3).

    So one loop is not enough, only two loops can be used.

    Finally, let's design these two cycles. The first loop does only one thing, which is to add each element in the array one after the other to get the total score. At the end of the cycle, we can calculate the average score.

    Then we find that tasks 2 and 3 can be performed in the second loop at the same time, first determine whether each element is less than the average, if it is less, then store it in a new array and increase the variable j used to count the number of people, so that after the cycle is over, we will get the number of people and the new array.

    Pure hand-played, plus personal analysis.

  10. Anonymous users2024-02-02

    Here you use for twice because you need to solve the problem, the first for loop, add all the scores, and then calculate the average score;

    In the second for loop, all scores are compared with the average score, and those below the average score are put into the below array;

    How many for loops are used, depending on the need to solve the problem (exactly like this problem).

  11. Anonymous users2024-02-01

    In this problem, the two for are separate, they have nothing to do with each other, and the deletion of one does not affect the other, and it is not a superposition of the for cycle.

    A cycle uses a for, and each item in this cycle has a cycle, and then a for, and there is a ...... for recycling under the cycle

    For example, there are 5 classes in a level, with one for, a class has four groups, the first for loop is superimposed on the second for loop, there are 12 people in one group, and the third for ...... is superimposed

    In fact, there is no need to consider the problem of using it many times for recycling, it is natural to use it, and it should be used naturally.

  12. Anonymous users2024-01-31

    The answer is 10, choose D

    Because it is calculated 1+2+3+4+5+......program, but once the loop reaches 5, it has not been added, and the loop is over, so only 4 is added, and the result is 1+2+3+4=10

  13. Anonymous users2024-01-30

    Why, you can look at the difference between break and continue.

  14. Anonymous users2024-01-29

    K++, which can be understood as the following implementation:

    When k = 5, k++ = 5 satisfies the condition, and after the execution of the statement, k = 6;

    Perform k++ = 5 again, and after executing that judgment, k = 7, so the final result is 7

  15. Anonymous users2024-01-28

    k=7;

    k++ means that k adds 1 to itself after participating in this operation.

    Decompose the for loop:

    When k=5, k<=5 satisfies, so enter the next cycle, k++ when k=6, k<=5 is not satisfied, jump out of the loop, k++ out of the loop, k=7

  16. Anonymous users2024-01-27

    k has a value of 6 at the time of the last cycle, and then the cycle condition is judged (k++<=5 again) and +1 again

    The output is 7

Related questions
9 answers2024-05-23

In program development, if the program is not written reasonably, you will often encounter the problem of dead loop, but you may have never been in contact with **, and you don't know much about what "dead loop" is, haha, then I'll tell you a joke and you will understand: The boss said to the secretary: I'll take you to Beijing for a walk these days. >>>More

9 answers2024-05-23

do while not

Output line. for i=1 to 3 >>>More

6 answers2024-05-23

Water is constantly moving and transforming in the vast system of the water cycle, so that the water resources are constantly renewed. The water cycle maintains the dynamic balance of water worldwide. The water cycle carries out energy exchange and material transfer. >>>More

9 answers2024-05-23

Issue.

1. If you know (and should know in middle school) that the "blood vessels" of blood circulation include arteries, capillaries and veins, you should know that the transfer of all substances occurs in the capillary segment. >>>More