Finding the closest number divisible by 7 for a certain number.
Finding the closest number
divisible by 7 for a certain number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ManualResetEvent_
{
class Number
{
public static void Main()
{
numberCloseTo(5676);
Console.ReadLine();
}
public static void numberCloseTo(int mynumber)
{
int low,
high, next_number, matchedvalue;
if (mynumber % 7 == 0)
{
Console.WriteLine("The number
{0} is a multiple of 5" + mynumber);
matchedvalue = mynumber;
}
else
{
low = mynumber - 7;
high = mynumber + 7;
for (int i = low; i < high; i++)
{
if (i % 7 == 0)
{
next_number = i + 7;
if((mynumber - i) <
(next_number - mynumber)&&(next_number < high))
{
Console.WriteLine("The number is :" +
i);
matchedvalue = i;
}
else if ((mynumber - i) >
(next_number - mynumber) && (next_number < high))
{
Console.WriteLine("The number is :" +
next_number);
matchedvalue =
(mynumber - i);
}
}
}
}
}
}
}
Comments
Post a Comment