Answer:
function
increase_elements_by_x (list, x)
{
var tplist = [];
for (i = 0; i < list.length; i++)
{
tplist[i] = list[i] + x;
print (tplist[i])}
return tplist;
}
var list =[1, 3, 5];
var copyList;
var x = 3;
copyList = increase_elements_by_x (list, x);
print (copyList);
Explanation:
Create a list named list with initial data 1,3,5.
Create a function name increase_elements_by_x which takes list and number as argument.Create empty list tplist. Loop through list, for ever index add x to list[index] and save to an empty list tplist. After loop is exited return tplist.
create a variable copylist and set it to increase_elements_by_x. Value returned by increase_elements_by_x will be saved in copylist. print copy list to see content of copy list.
public static void main()
{
String s = Console.ReadLine();
int len = s.length();
Char startletter = s[0];
Char endletter = s[len-1];
string midletter = ‘’;
if(len % 2 ==0)
midletter = s[len/2] + s[(len/2) +1]
else
midletter = s[len/2];
Console.WriteLine(startletter + midletter + endletter);
}
Here the logic is that, startletter is obtained using the index ‘0’, the last letter is obtained by calculating the “length of the string” and subtract 1 to get the “last index” of the given string.
Middle letter is calculated by first finding whether the given string length is “odd or even” and based on that index(es) are identified.
All we need is Faith, Trust, and Pixie Dust...