Tuesday, July 28, 2009

Hi , I tried ti determine the number of digites in console application in C# Like this but I dont know why it?

does not work.


string input;


int num,c,d;


input = Console.ReadLine();


num = int.Parse(input);


c = 0;


d = num;





while (d !=0 )


{


d = d / 10;


c = c + d;


c = c + 1;


}


Console.WriteLine(c);





}


}


}

Hi , I tried ti determine the number of digites in console application in C# Like this but I dont know why it?
Hey, why did u wtrte "c=c+d"??


Delete that line, then run the program, and let us know what happened.





Good luck


Bye
Reply:You might want to consider just converting the number to a string and measuring the length of the string.


This way,you will avoid unnecesary complexity
Reply:This line is extra:


c = c + d;











so:





while (d !=0 )


{


d = d / 10;


c = c + 1;


}


No comments:

Post a Comment