Muhammad Nadeem

Muhammad Nadeem

  • NA
  • 548
  • 66.2k

How to more Details

May 5 2016 3:18 AM
Please guide me. How to add some more lines of code in this program. How to do some more explaination in this code.
 
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
HeavyDeciCount(9872, 9884);
}
public static void HeavyDeciCount(int x, int y)
{
var totalHeavyCount = 0;
for (int i = x; i <= y; i++)
{
var avg = i.ToString() // convert an integer to string - "9872"
.Select(o => Convert.ToInt32(o.ToString())) // convert each string character to integer - 9, 8, 7, 2
.ToArray() // create array of all integers - { 9, 8, 7, 2 }
.Average(); // calc the average of the array numbers
var isHeavy = false;
if (avg > 7)
{
isHeavy = true;
totalHeavyCount++;
}
Console.WriteLine(i + " " + avg + " " + (isHeavy ? "Yes" : "No"));
}
Console.WriteLine("Total heavy count: " + totalHeavyCount);
Console.Read();
}
}
}

Answers (1)