Software & Finance





C# Display the numbers containing the digit '5' in between 100 to 200





 

I have given here C# code to Display the numbers containing the digit '5' in between 100 to 200. The idea here is to use the mod and divide operator to get the single digit and check whether it is equal to 5 or not.

 

 

Source Code


using System;

using System.Collections.Generic;

using System.Text;

 

namespace Count

{

   class CountSample

   {

      static void Main(string[] args)

      {

        

         int sum = 0;

         int i, a, b, c;

         for(i = 100; i <= 200; i++)

         {

            a = i % 100;

            b = a / 10;

            c = a % 10;

            if(b == 5 || c == 5)

               System.Console.WriteLine("{0}", i);

            sum += i;

         }

         System.Console.WriteLine("\n\nSum = {0}\n\n", sum);

      }  

   

   }

 

}

 

 

Output


105

115

125

135

145

150

151

152

153

154

155

156

157

158

159

165

175

185

195

 

Sum = 15150