-
Notifications
You must be signed in to change notification settings - Fork 0
/
Range II.cs
109 lines (106 loc) · 4.21 KB
/
Range II.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
namespace Range_II
{
class Program
{
static void Main(string[] args)
{
int a, b, valueint; string interval, value = string.Empty;
Console.WriteLine("Write the interval: ");
interval = Console.ReadLine();
if (interval.Contains("(") && interval.Contains(")"))
{
for (int i = 0; i<interval.Length; i++)
{
if (char.IsDigit(interval[i]))
{
value += interval[i];
}
}
if (value.Length > 0)
{
valueint = int.Parse(value);
b = valueint % 10; valueint /= 10;
a = valueint % 10; valueint /= 10;
Console.WriteLine("The open interval ({0},{1}) contains: ", a, b);
for (int iteration = a; iteration<b-1; iteration++)
{
Console.Write(iteration + 1 + ", ");
}
Console.WriteLine();
Console.WriteLine("The endpoints of the interval are: " + (a + 1) + "," + (b - 1));
}
}
if (interval.Contains("[") && interval.Contains("]"))
{
for (int i = 0; i < interval.Length; i++)
{
if (char.IsDigit(interval[i]))
{
value += interval[i];
}
}
if (value.Length > 0)
{
valueint = int.Parse(value);
b = valueint % 10; valueint /= 10;
a = valueint % 10; valueint /= 10;
Console.WriteLine("The closed interval [{0},{1}] contains: ", a, b);
for (int iteration = a; iteration <=b; iteration++)
{
Console.Write(iteration + ", ");
}
Console.WriteLine();
Console.WriteLine("The endpoints of the interval are: " + (a) + "," + (b));
}
}
if (interval.Contains("(") && interval.Contains("]"))
{
for (int i = 0; i < interval.Length; i++)
{
if (char.IsDigit(interval[i]))
{
value += interval[i];
}
}
if (value.Length > 0)
{
valueint = int.Parse(value);
b = valueint % 10; valueint /= 10;
a = valueint % 10; valueint /= 10;
Console.WriteLine("The half-open interval ({0},{1}] contains: ", a, b);
for (int iteration = a; iteration < b; iteration++)
{
Console.Write(iteration + 1 + ", ");
}
Console.WriteLine();
Console.WriteLine("The endpoints of the interval are: " + (a + 1) + "," + (b));
}
}
if (interval.Contains("[") && interval.Contains(")"))
{
for (int i = 0; i < interval.Length; i++)
{
if (char.IsDigit(interval[i]))
{
value += interval[i];
}
}
if (value.Length > 0)
{
valueint = int.Parse(value);
b = valueint % 10; valueint /= 10;
a = valueint % 10; valueint /= 10;
Console.WriteLine("The half-open interval [{0},{1}) contains: ", a, b);
for (int iteration = a; iteration <=b-1; iteration++)
{
Console.Write(iteration + ", ");
}
Console.WriteLine();
Console.WriteLine("The endpoints of the interval are: " + (a) + "," + (b-1));
}
}
Console.ReadKey();
}
}
}