Questions tagged [arithmetic-expressions]

An arithmetic expression is an expression that results in a numeric value. There are two kinds of numeric values, integers (whole numbers), and real or floating point numbers (numbers containing a decimal point).

677 questions
-3
votes
1 answer

Adding Strings and ssize_t?

I have a question on adding strings and data types. What does it mean to use them in such arithmetic? Does body + size mean that it is creating a new block of memory that includes both of them? The following is just an excerpt of the code: char*…
Jessup Jong
  • 31
  • 1
  • 1
  • 6
-3
votes
1 answer

How Matlab can be so slow in high dimensional matrix arithmetic operation?

I'm impressed by the low speed of Matlab matrix arithmetic operation in my code as follows: pitemp=zeros(nz,na,nb,nk,nxi,nann,nbn,nkn); …
Woodpecker
  • 17
  • 3
-3
votes
1 answer

Arithmetic operator precedence quirk

In C, since the addition operator (+) takes precedence before subtraction (-), I assume the following expression will return 0: 5 - 1 + 4 But no, it return 8 instead. Why is that? P.S.: The expression was tested in Objective-C. EDIT: Apparently my…
Andree
  • 3,033
  • 6
  • 36
  • 56
-4
votes
3 answers

Someone please explain me the logic behind this opration

#include int main(){ int a=10,b=3,c=2,d=4,result; result = a+a*-b/c%d+c*d; printf("%d",result); } How is this program giving 15 as the output.. I did not understand the logic behind the operation.. Can someone please tell me…
-4
votes
1 answer

Overload an Arithmetic Operator C++

I have to do the following: In Cash.h, add a declaration inside the Money namespace for an operator overload for the + operation; this should take two Cash operands and return a new Cash value. Remember that the declaration will consist of the…
-4
votes
2 answers

Java Divide by Zero - Calculator

I have created a Java calculator, however i need to add code for when the number is divided by zero i set the result to be zero. Everything else is working i just don't know where to add this statement. heres the code: public class Calculator { //…
RHH
  • 41
  • 1
  • 9
-4
votes
1 answer

Questions about J9

-Is it true that OpenJ9 has non overflow and underflow arithmetic modes for float and double? What needs to be done to obtain that? If not, can this be changed somehow? -Is OpenJ9 a compiler or a runtime or both? -Is OpenJ9 Windows compatible and…
user1544
  • 155
  • 4
-4
votes
1 answer

How to get absolute value for a double value within a function (Without using math.h)

how can I get absolute value for the double diff in this case? double cos_delta(double x, double delta) { int n = 1; // n should start with 1 because it is the number of terms double diff = cos_N(x, n ) - cos_N(x, n - 1); // n and n-1 instead…
Saeed
  • 1
  • 3
-4
votes
1 answer

Method to calculate sum of product of two consecutive numbers

Write a Java method to calculate the following summation: 2×3+3×4+4×5+...+97×98+98×99 Or more generaly, the sum from i = 2 to 98 of i*(i+1). Can this be done with recursion or only with a for/while loop?
student96
  • 1
  • 2
-4
votes
4 answers

Calculate Average Java

I'm trying to calculate the average of the student scores and as it stands I'm struggling with the calculation part. In my assignment I was asked to caulculate the avg age of three students and avg. heigth of three students. Could someone please…
Jake Zywiol
  • 21
  • 1
  • 1
  • 8
-5
votes
1 answer

How can I avoid Arithmetic exception in this C++ code?

I don't know why my program shows runtime-error when my input is 100 , for instance. If I input a smaller value, like 5, it works just fine! #include using namespace std; int main() { int noCopy,currentPrinter = 1; cin >>…
-5
votes
2 answers

Arithmetic optimization

How to optimize the following (convert arithmetic to bit-wise operations)? Optimize: int A = B * 4 int A = B * 72 int A = B % 1 int A = B % 16 int A = (B + C) / 2 int A = (B * 3) / 8 int A = (B % 8) * 4 Saw these questions in interview.
A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
-5
votes
1 answer

What does this C program do?

#include int main(){ char c; while((c = getchar()) != EOF){ if(c >= 'A' && c <= 'Z') c = c - 'A' + 'a'; putchar(c); } return 0; } Came across this C code in MIT's Practical Programming in C.…
nAiN
  • 55
  • 2
  • 7
-5
votes
1 answer

Which of the following arithmetic expressions is identical to the expression a += b * c

A - Which of the following arithmetic expressions is identical to the expression a += b * c ? a = (a + b) * c a = b * c a = a + b * c a = ++b * c None of the above B - Which of these following expressions is wrong…
-6
votes
1 answer

Android: Division and subtraction always equal 1.0

I'm making a simple calculator but when I try to divide I always get 1.0 and when I subtract I always get zero. Addition and multiplication work fine. I've read similar questions such as : Why does integer division code give the wrong…
Eklassen
  • 13
  • 1
  • 6
1 2 3
45
46