Hi every one I have a question.
I joint a c++ class and they taught us how to make a program that can counts the
digits of a number . But there was something I didnt understand . What does this "c" here do? why did we printed c at the end (cout<<c;)? please help
Why don't you type in a multi-digit number a few times and see what answers you get. Then go back and read what the program is doing. eg 3, 32, 512, 1024 then 56789
Hi,
c here is used as a counter.
it basically counts the digit.
lets assume n = 100
when while is entered n=n/10 we get n = 10
and c becomes 1 as c++ is written
then again we enter while as still n>0
now n = n/10 so n = 1
c becomes 2
again the same process is repeated and we get c = 3
so c is actually counting digits and we call it counter.