Code:
// program asks user to enter a number
//the program then prints how many digits user entered.
//code works.
//what I don't understand is how the for loop works.
//can someone explain each step the for loop takes up until it prints out the answer. thx
#include <stdio.h>
int main(void)
{
int n,i,x;
printf("Please enter a positive integer: ");
scanf("%d",&n);
x=n; //dummy variable
for ( i=0; n>0; i++) //for loop
{ n=n/10; } //reduces the number "n"
printf("Number %d is %d digits long.\n",x,i);
return(0);
}