7-7 C# 1.12 区间找数
编写控制台应用程序,根据用户输入的a、b、c、d值(均为正整数且a不大于b),输出在[a, b]区间中能被c整除,但是不能被d整除的数。
输入格式:
用户在一行中输入四个正整数,分别对应a、b、c、d,相邻的两个数中间用一个空格间隔。
输出格式:
输出在[a, b]区间中能被c整除,但是不能被d整除的数,每五个数换行(每行中的两个相邻数字之间用一个空格间隔)。
输入样例:
在这里给出一组输入。例如:
1 20 2 3
输出样例:
在这里给出相应的输出。例如:
2 4 8 10 14
16 20
class Solution7_7
{
public static int a, b, c, d;
public static string input;
static void Main(string[] args)
{
List<int> list = new List<int>();
string[] input = Console.ReadLine().Split(' ');
a = Convert.ToInt32(input[0]);
b = Convert.ToInt32(input[1]);
c = Convert.ToInt32(input[2]);
d = Convert.ToInt32(input[3]);
for (int i = a; i <= b; i++)
{
if (i % c == 0 && i % d != 0)
{
list.Add(i);
}
}
for (int i = 0; i < list.Count; i++)
{
Console.Write(list[i]);
if ((i + 1) % 5