Saturday, May 22, 2010

C# Questions - Please Help ASAP!?

i am having some difficulty with these C# questions! i will give you the questions and 4 possible answers, please can you provide me with the correct answer and please explain how you got that answer.... thanks in advance





1. What does the following algorithm produce when n is 3?


set sum to 10.


set i to 1.


input n.


while i is less than or equal to n do


{


take i from sum.


increment i.


}


output sum.





a. 9


b. 7


c. 4


d. 1





2. What would be output by the following section of code ?


int A[4] = {1 , 2, 3, 4};


int i;


for (i=0; i%26lt;4; i++)


{


A[i] = A[i] + A[i];


}





Console.WriteLine (A[i] );





a. 4


b. 0


c. 8


d. 6





3. Given the following method (you may assume it has all compiled correctly so there are no syntax errors), what will be output?





public static void printloop()


{


int i;


for (i=1; i%26lt;9; i++) ;


if (i%2 = = 0) ;


Console.WriteLine (i + " ");


}





a. 2 4 6 8


b. 8


c. Nothing is output.


d. 2 4 6

C# Questions - Please Help ASAP!?
First problem the answer is 4.


Second problem the answer is 8


Third problem the answer is 2, 4, 6, 8.





Why?





1st Problem:





sum 10


i 1


n 3





while i%26lt;=n


{


sum = sum -1


}


output sum





10 - 6 = 4, thats the output of sum





Second problem:





You end up having the value of 4+4 which is 8.





And for the last problem, the only numbers that will give you %2==0 are 2, 4, 6, 8


No comments:

Post a Comment