C# program
write a program to count number of zero between 1 to 1000 using c#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 30, 2013, 7:04 AM EDT
int numZero = Enumerable.Range(1, 1000).Sum(n => n.ToString().Count(c => c == '0'));
Although this isn't the most efficient way to do it, the logic is to:
1. Convert each number between 1 and 1000 to a string
2. Count how many characters are '0' in this string.
3. Sum the results of step 2.
Assuming you're not allowed to use LINQ, I'd reproduce this logic using traditional code.
Nitesh KejriwalRank #253 · 9.9K reputationPosted Aug 30, 2013, 4:27 AM EDT