Question

In: Computer Science

Explain how to use the C# shortcut arithmetic operators -=, *=, and /=.

Explain how to use the C# shortcut arithmetic operators -=, *=, and /=.

Solutions

Expert Solution

using System;

namespace Demo {

class MyApplication {

static void Main(string[] args) {
   int a = 5;
           a += 9;
           Console.WriteLine(a); // output: 14
          
           a -= 4;
           Console.WriteLine(a); // output: 10
          
           a *= 2;
           Console.WriteLine(a); // output: 20
          
           a /= 4;
           Console.WriteLine(a); // output: 5
          
           a %= 3;
           Console.WriteLine(a); // output: 2
}
}
}

x op= y equivalent x = x op y ( op   +,-,*,/ )

x+=y equivalent x=x+y

x-=y equivalent x=x-y

x*=y equivalent x=x*y

x/=y equivalent x=x/y


Related Solutions

USING C++: Consider the precedence levels of the relational, logical, and arithmetic operators of the PySub...
USING C++: Consider the precedence levels of the relational, logical, and arithmetic operators of the PySub language to be as follows (NOTE: 5 has highest precedence and 0 lowest): 5 *, /, % 4 +, - 3 <, <=, >, >=, !=, == 2 not 1 and 0 or 1.  Infix-Postfix Conversion and Evaluation with Logical and Relational operators – Convert the following infix expression to a postfix expression and evaluate the result (assume that true=1 and false=0). Provide both the...
C++ OOP Make a program to evaluate infix arithmetic expressions containing integer operands and the operators...
C++ OOP Make a program to evaluate infix arithmetic expressions containing integer operands and the operators + (addition), - (subtraction), * (multiplication), / (division) and pairs of parentheses, properly nested. Use the following two-stack algorithm (by E. W. Dijkstra): If the next token in the expression is an integer, push the integer onto the value stack. If the next token in the expression is an operator, If the operator stack is empty or the priority of the operator is greater...
List the arithmetic operators used in BASIC and state their priorities of execution in a statement....
List the arithmetic operators used in BASIC and state their priorities of execution in a statement. Also give a list and briefly explain the functions of the most popular statements.(IN OWN WORDS MIUST BE)
Can someone please explain how to use ladder operators for the addition of angular momentum, it...
Can someone please explain how to use ladder operators for the addition of angular momentum, it can be found in chapter 4 of Griffiths intro to quantum mechanics. Please provide some examples of this, you may use problems from chapter four of the book. Thank you.
Lisp In the language Lisp1 , each of the four basic arithmetic operators appears before an...
Lisp In the language Lisp1 , each of the four basic arithmetic operators appears before an arbitrary number of operands, which are separated by spaces. The resulting expression is enclosed in parentheses. The operators behave as follows: (+ a b c ...) returns the sum of all the operands, and (+) returns 0. (- a b c ...) returns a - b - c - ..., and (- a) returns -a. The minus operator must have at least one operand....
Is there a shortcut or simpler way to get the same output in C ? #include...
Is there a shortcut or simpler way to get the same output in C ? #include <stdio.h> #include <time.h> #include <stdlib.h> #define OFFSET 1 #define RANGE 53 int RandomInteger(int, int); int PrintInstructions(); int main() { //six integer variables int a, b, c, d, e, f; //one integer for num of sets int numSets; srand(time(NULL)); while (1) { int i; numSets = PrintInstructions(); if (numSets == 0) { printf("* You have choosen to exit the application.\n"); break; } for (i =...
Using the descriptions below, write a scanner for numbers, symbols, comments, arithmetic operators, and parenthesis in...
Using the descriptions below, write a scanner for numbers, symbols, comments, arithmetic operators, and parenthesis in Racket or scheme. - a number is one or more digits | zero of more digits followed by a decimal point followed by one or more digits | one or more digits followed by a decimal point followed by zero or more digits - a symbol is      one or more characters from the set [_A-Za-z] followed by zero or more characters from the...
Postfix Arithmetic Operation (C++) Friday, 27 September 2019, 04:21 PM Use stack to implement postfix arithmetic...
Postfix Arithmetic Operation (C++) Friday, 27 September 2019, 04:21 PM Use stack to implement postfix arithmetic operation. Input Many test cases until EOF. Each line is a postfix arithmetic operation formula. There is no blank between the numbers, and the number only is 0-9. Output The result of each line. But if the postfix arithmetic operation formula is wrong (it means you can't get the correct answer), please output "Input Error". Sample Input 35+ 3+5 63/14-*3+8- Sample Output 8 Input...
using python without external libaries Using integer arithmetic operators '+' and '-', print all combinations that...
using python without external libaries Using integer arithmetic operators '+' and '-', print all combinations that sum up to 'sum' by inserting the operators between digits in 'number'. example for 'number=123456789' and 'sum = 0' Print the output using the terminal: Output should be exactly like this from 1 - 22 1 : +1+2-34-56+78+9=0 2 : +1-2-34+5+6+7+8+9=0 3 : +1-23-4-56-7+89=0 ... 12 : -1+2+34-5-6-7-8-9=0 13 : -1+23+4+56+7-89=0 14 : -1-2+34+56-78-9=0 ... 22 : -12-34+56+7-8-9=0
--Know how to do tuple comparison in queries. --Know how to use operators with nulls, and...
--Know how to do tuple comparison in queries. --Know how to use operators with nulls, and know the is null and is not null operators. --Be able to use the aggregate functions avg, count, min, max, and sum and know how to use them with group by and having. --Know how aggregation works with null values. Study guide can you please provide examples
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT