-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path4_Number.cs
More file actions
61 lines (56 loc) · 1.69 KB
/
4_Number.cs
File metadata and controls
61 lines (56 loc) · 1.69 KB
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
using System;
/*
* Create a class Number having instance variable x and y both in integer,
* default constructor that set the value of x and y to 0,
* parameterized constructor that sets the value of x and y,
* method findOdd() that calculates the odd no. occurring between x and y and display the result,
* method findEven() that calculates the even no. occurring between x and y and display the result.
* Now, create some instance of Number and invoke all the methods.
*/
namespace Practical1
{
class Number
{
// Instance variables
private int x;
private int y;
// Default constructor setting x and y to 0
public Number()
{
x = 0;
y = 0;
}
// Parameterized constructor setting x and y
public Number(int x, int y)
{
this.x = x;
this.y = y;
}
// Method to find and display even numbers between x and y
public void FindEven()
{
Console.Write("Even numbers between " + x + " and " + y + ": ");
for (int i = x; i <= y; i++)
{
if (i % 2 == 0)
{
Console.Write(i + " ");
}
}
Console.WriteLine();
}
// Method to find and display odd numbers between x and y
public void FindOdd()
{
Console.Write("Odd numbers between " + x + " and " + y + ": ");
for (int i = x; i <= y; i++)
{
if (i % 2 != 0)
{
Console.Write(i + " ");
}
}
Console.WriteLine();
}
}
}