Problem solving using c#