- 2
what is output
static int calc(int from, int to, int step=1) { int res=0; for(int i=from;i<to;i+=step) { res += i; } return res; } static void Main(string[] args) { int res = ( 2, 99, 5); Console.WriteLine(res); }
6 Respostas
+ 1
there is an error
+ 1
static int calc(int from, int to, int step=1) {
int res=0;
for(int i=from;i<to;i+=step) {
res += i;
}
return res;
}
static void Main(string[] args)
{
int res =
calc
(
step:
2,
to:
99,
from:
5);
Console.WriteLine(res);
}
0
990 after correction
0
Call the method using named arguments with the values 5 for "from", 99 for "to" and 2 for "step":
static int calc(int from, int to, int step=1) {
int res=0;
for(int i=from;i<to;i+=step) {
res += i;
}
return res;
}
static void Main(string[] args)
{
int res =
calc
(
step:
2,
to:
99,
from:
5);
Console.WriteLine(res);
}
0
static int calc(int from, int to, int step=1) {
int res=0;
for(int i=from;i<to;i+=step) {
res += i;
}
return res;
}
static void Main(string[] args)
{
int res = calc ( step: 2, to: 99, from: 5);
Console.WriteLine(res);
}
0
Named Arguments
Call the method using named arguments with the values 5 for "from", 99 for "to" and 2 for "step":
static int calc(int from, int to, int step=1) {
int res=0;
for(int i=from;i<to;i+=step) {
res += i;
}
return res;
}
static void Main(string[] args)
{
int res =
calc
(
step:
2,
to:
99,
from:
5);
Console.WriteLine(res);
}