Machine Problem 5.4.
Write a program using two-‐dimensional arrays that determines the ODD numbers among the12 input values typed fromthe keyboard and prints the list of these ODD numbers.
Sample input/output dialogue:
Enter twelve numbers: 8 9 10 7 25 30 69 101 798 10111 10023
Odd numbers are: 9 7 25 69 101 10111 10023
Here is my program:
static void Main(string[] args)
{
int[,] arr = new int[12,1];
Console.WriteLine("Enter twelve numbers: ");
for(int i = 0; i < arr.Length; i++)
{
arr[i,0] = Int32.Parse(Console.ReadLine());
}
Console.Write("Odd numbers are: ");
foreach(int i in arr)
{
if (i % 2 != 0)
{
Console.Write(i + " ");
}
}
}
Comments
Leave a comment