Find digits which has zeo

rteswaran

New member
Joined
Jan 4, 2025
Messages
2
Programming Experience
10+
I am looking solution for below requirements without using linq.

Return total count of zeros found between zero to 100.

Here we should consider less iteration when use for loop because let's say if I want to count for 10000 then loop will executed 10000 times
 
This seems pretty obviously to be homework, so we're not going to just cheat for you. You need to put some thought into the problem and come up with the logic, then try to implement that logic. If you have trouble at the implementation stage then post here and tell us what you did and whay happened and we can help you fix it. We can also help you with the logic part but, again, we're not here to just do it for you. You tell us what you're thinking and we can tell you whether you're on the right track, possibly giving you a point in the right direction if you're not
 
As a quick aside, all that LINQ does is hide the loops from you. The loops are still happening under the covers.

Also, consider that the problem is solvable without loops by using pure mathematical operations, but it is slightly easier by doing loops much like division can be done by doing the division operation, but can be done via repeated subtractions.
 
var count = 0;
var input = 10000;
for(var i=0; i<=input; i++){
var numberString = i.ToString();
foreach(var c in numberString){
if(c=='0'){
count++;
}
}
}

We can achieve using about code but I don't want to iterate for 10000 times
 
Back
Top Bottom