string[] num = {"1"",2"",3"",4"",5"",6"}; // this array is used to display
You want to divide it into two arrays:
How do I divide an array into two arrays?
string[] odd = {"1","3","5"};
string[] even = {"2","4","5"};
Try using LINQ of C#.
using System.LINQ;
// ...
var odd = num.Where(str => (Int32.Parse(str)%2)==1);
var even = num.Where(str => (Int32.Parse(str)%2)==0);
Reference link
[1] https://www.dotnetperls.com/linq
Code Execution Example
using System;
using System.Linq;
public class Hello1 {
public static void Main() {
string[] num = {"1","2","3","4","5","6"};
var odd = num.Where(str => (Int32.Parse(str)%2)==1);
Console.WriteLine("ODD");
foreach (string value in odd)
{
Console.WriteLine(value);
}
var even = num.Where(str => (Int32.Parse(str)%2)==0);
Console.WriteLine("EVEN");
foreach (string value in even)
{
Console.WriteLine(value);
}
}
}
575 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
586 PHP ssh2_scp_send fails to send files as intended
624 GDB gets version error when attempting to debug with the Presense SDK (IDE)
928 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.