CSharp · Console
// An x pixels wide graphics screen is filled with n vertical stripes of almost equal widths
// (the stripe’s widths differ by 1 at most).
// Find the total number of narrow stripes (the ones that have smaller widths than other ones).
// The program inputs x and n and outputs the number of narrow stripes.
using System;
using System.Diagnostics;
public class Program
{
public static int InputInt(string prompt)
{
Console.Write("Enter " + prompt + ":");
return Convert.ToInt32(Console.ReadLine());
}
public static void Main(string[] args)
{
int width = InputInt("screen width");
int nStripes = InputInt("number of stripes");
Trace.Assert(width > 0 && nStripes > 0);
int nWideStripes = width % nStripes;
Console.WriteLine("number of narrow stipes: " + (nStripes - nWideStripes));
Console.WriteLine("number of wide stipes: " + nWideStripes);
}
}