Read a set of numbers from the command-line argument in the form of a
comma-separated list (we follow the option convention of
mcs
) like this,
mono main.exe -numbers:1,2,3,4,5 > Out.txt
and print
these numbers together with their sines and cosines (in a table form)
to the standard output. Something like
public static void Main(string[] args){
foreach(var arg in args){
var words = arg.Split(':');
if(words[0]=="-numbers"){
var numbers=words[1].Split(',');
foreach(var number in numbers){
double x = double.Parse(number);
WriteLine($"{x} {Sin(x)} {Cos(x)}");
}
}
}
}
The program can get the numbers from the command-line directly,
mono main.exe -numbers:1,2,3,4,5 > out.txt
or, alternatively, if the line of numbers is too long, one can write
the numbers into a file and then "cat"
the file into the command line,
echo "-numbers:1,2,3,4,5" > inputfile
mono main.exe $(cat inputfile) > out.txt
The length of the command line is limited though, so the size of the file
should not exceed your command line limit (probably about 2 megabytes).
Read a sequence of numbers, separated by a
combination of blanks (' '), tabs ('\t'), and newline characters ('\n'),
from the standard input and print these numbers together with their sines
and cosines (in a table form) to the standard error. Something like
char[] split_delimiters = {' ','\t','\n'};
var split_options = StringSplitOptions.RemoveEmptyEntries;
for( string line = ReadLine(); line != null; line = ReadLine() ){
var numbers = line.Split(split_delimiters,split_options);
foreach(var number in numbers){
double x = double.Parse(number);
Error.WriteLine($"{x} {Sin(x)} {Cos(x)}");
}
}
The program can be run as
echo 1 2 3 4 5 | mono main.exe 2> out.txt
or
echo 1 2 3 4 5 > input.txt
mono main.exe < input.txt 2> out.txt
or
echo 1 2 3 4 5 > input.txt
cat input.txt | mono stdin.exe 2> out.txt