Thursday, July 30, 2009

Hello everyone I'm taking this intro to C# class and need some help solving this problem.?

int a, b, c;


d= -8;


a= 1 * 2 +3;


b= 1+2*3;


c= (1 + 2) * 3;


c= a + b;


d= -d;





What will be displayed or what will the values be when executed and how do you solve this? If anyone can help me I'd greatly appreciate it!

Hello everyone I'm taking this intro to C# class and need some help solving this problem.?
a=5


first it ll give preference to 1*2 and the result ll be added to 3





b=7


first the preference to 2*3 and the result is added with 1





c=12


At first the value is c=9


becoz it gives preference to () then the result is multiplied


and also the result of a and b are added and reassigned to c so new value is c=12





d=8


When u negate the negative it bcomes +ve





Rules:-


Precedence is first given to ( )


then, * and /


then to + and -
Reply:I am happy that i have teached in a right way to some one. Good luck. Learn well. Report It

Reply:As this line of code runs, it will do the following:





first line: creates three integer variables





second line: since 'd' was not "created," this will probably cause an error. To fix this you would need to add a 'd' into the first line.





third line: evaluates the equation on the right side of the equals and assigns the result to the variable 'a'. Now a = 5.





fourth line: evaluates the equation on the right side of the equals and assigns the result to 'b'. Order-of-operations will cause the multiplication to occur first, so now b = 7.





fifth line: the brackets will now be solved first (brackets come before multiplication and division, which come before addition and subtraction). Now c = 6.





sixth line: the current values of 'a' (5) and 'b' (7) will be added together. This new value (12) will replace the old value of c, which was 6. Now c = 12. The values of 'a' and 'b' don't change.





seventh line: again, this will not work unless 'd' is initialized as a variable. This will cause an error.





In this section of code, there is nothing being displayed.
Reply:first line tells you that there are three integer variables a,b and c.


the other lines just assign some values to these variables. But nothing would be displayed when the code is run. Variable d is not even initialized, so the code may gives error when it is run.
Reply:Unless C# changed drastically from C and C++, the term 'int' means integer, which in thise case is used to set up three integer variables "a," "b," and "c." D (has not been initialized and this is an error) is given the value -8 at first. Then A is given the value 1*2 + 3 = 5. B is given the value 1+2*3 = 7. C is given the value (1+2)*3 = 9. But then C is given the new value a+b = 5+7 = 12. D is then given the inverse of itself, which is now +8. There is no output because there are no commands in the code to display the values.
Reply:Nothing will be displayed. All it is telling the computer is that you are putting in values for inputs a, b, and c. int basically stands for input. Aside from giving the letter numeric values, it also is telling the computer the relationship between a, b, and c. You might be better off learning C++ first. C# is a newer version and (in my opinion) slightly harder to understand if you're new to the coding world.


No comments:

Post a Comment