loop Statements and iterative algorithms are closely related knowledge, can be zoned for the same module Master , for many problems (such as the most common sequence summation problem), loop + iterative scheme, than the loop nested , be more efficient, clean.
Use of the law: as long as the sequence of the preceding paragraph and latter exist in contact, you can consider the iterative algorithm .
Such as
Example of using a loop + iteration scheme:
Problem Description: Ask for a value of SN=A+AA+AAA+...+AA...A, where a is a number.
For example 2+22+222+2222 (at this time a=2,n=4), A and n are entered by the keyboard.
1#include"stdafx.h"2 3 intMain ()4 {5 intA, N, sum (0), T (2);6scanf_s ("%d%d", &a, &n);7 8 for(inti =0; I < n; i++)9 {TenSum + =T; One for At = T *Ten+A; - } - theprintf"%d", sum); - - return 0; -}
=
"C language and programming" loops and Iterations