Respuesta :
write program "count the number of digit" with loop.
for example :
#include <stdio.h>
int main() {
long long n;
int count = 0;
printf("Enter some an integer: ");
scanf("%lld", &n);
// iterate at least once, then until n becomes 0
// remove last digit from n in each iteration
// increase count by 1 in each iteration
do {
n /= 10;
++count;
} while (n != 0);
printf("Number of digits: %d", count);
}
so you can combine with loop logic, there are 2 kind of loop. do while, and while (do) :
1. while loop
basically, how while loop work is : take the condition first, after the condition still "true", every statements inside the while loop are executed. and then after the execution, the condition is evaluate again. and in the if the condition is evaluated to "false". the while loop terminates automatically.
- example :
int i=1;
while (i<=5)
{
Console.WriteLine("C# For Loop: Iteration {0}", i);
i++;
}
- output will be like :
C# For Loop: Iteration 1
C# For Loop: Iteration 2
C# For Loop: Iteration 3
C# For Loop: Iteration 4
C# For Loop: Iteration 5
2. do while
different with while loop, the "do while" executed at least 1 statements, true or false. then the condition is evaluated then. if the condition is true. the body of loop is executed. when the condition is false, do.. while loop terminated automatically.
- example :
int i = 1, n = 5, product;
do
{
product = n * i;
Console.WriteLine("{0} * {1} = {2}", n, i, product);
i++;
} while (i <= 5);
- output will be like :
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
For more information about the programming refer to the link: https://brainly.com/question/11023419
#SPJ4