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
-2
votes
1 answer

Beginner Arithmetic Math Operations (Java)

The question says 5 / 3 * 2.0 / (4 % 3) + 5 = 7.0 For some reason I don't understand why this makes sense at all. I start with dividing 5/6.0 = .83, then divide it by (4%3 which is 1) and add 5 but I'm not getting that answer. Can you explain it in…
-2
votes
3 answers

C unsigned char arithmetic operation does not works as expected

Here is the my snippet of code; Npp8u * imageHost; typedef unsigned char Npp8u; ... for (int i=0;i
erogol
  • 13,156
  • 33
  • 101
  • 155
-2
votes
1 answer

Variables as commands

I want to be able to use a set of variables that can stand in for mathematical operators. I am attempting to create a calculator as a learning exercise. I figure it would not be good to have the calculation occur every time a button is pressed, so…
-3
votes
0 answers

Why is the following C++ returning 1(true)?

#include int main() { std::cout << (2 == 2) && (10 < 5); } This code prints 1 (true), but I expect it to print 0 (false). I have tried to run the same code in several compilers, and they all give the same surprising result.
-3
votes
1 answer

How to write a python computer program that will take any valid arithmetic expression as a string and will output a list(or array of string)?

How to write a python computer program that will take any valid arithmetic expression as a string and will output a list (or array of string) of individual objects of the expression such as numbers, operators, variables, and…
-3
votes
1 answer

Python floats giving strange responses

I am writing a program that deals with adding floats to each other and found something weird. Examples ---INPUT--- print(1+0.1) print(1-0.1) ---OUTPUT--- 1.10000000000001 0.99999999999999 Why is this happening and how do I stop it?
-3
votes
1 answer

How to find missing value from equation using java?

User made some calculations using program..and printed it on paper.. But mouse cut some part from the paper. Now we have to create the program to find missing values. Example: 54 + 27 = HOLE 3241 + 4HOLE45=7281 We have to find the missing value at…
-3
votes
1 answer

Integer Division in Negative Numbers in Python

I'm testing big integers in Python; they are implemented as an object with sign and an array of digits. It's, basically, to describe Karatsuba Multiplication, and, for those big integers, I need the same behaviour like oridinary numbers with integer…
-3
votes
7 answers

How to system know that one over of cricket has 6 balls (Calculation) in Android

I'm developing a cricket app and I'm getting problems when I'm working with overs. We all know that whatever calculation is done in calculator is done with 10. For example : If there are total overs : 20, and current over 2.1 And I want to…
Pranav Fulkari
  • 187
  • 2
  • 12
-3
votes
1 answer

Why does std::chrono::time_point doesn't like arithmetics?

I was simply trying to measure the time passed between to time points: #include #include int main(){ // std::chrono::time_point start1; // <-- doesn't work // std::chrono::time_point end1; // <-- doesn't work auto…
daniel451
  • 10,626
  • 19
  • 67
  • 125
-3
votes
1 answer

How Do I Translate This Algebraic Expression In C++?

I need to write and execute a program in C++ that computes the value of the expression: 5x^2 + 12y / 3x , Where x = 12, And y = 9.8 This is what I have: int num1 = 12; float num2 = 9.8; float totalResult; totalResult = 5 * num1 * num2 + 12 * num2…
-3
votes
3 answers

Is there a floating point error in this obfuscated code?

As a puzzle I was given the following snippet of code yesterday with the question Why does this give 773.06..? var _ = 10, __ = 21, ___ = 38; var _______ = { _: { "yo":_/___*_+___ }}; var ___________ =…
Hugo Buff
  • 411
  • 5
  • 14
-3
votes
1 answer

Python: Converting inches to feet

I thought if I made the numbers float that it would give me a number with a decimal. height = 65.0 / 12.0 print height What I get back is 5 without the remainder when I use it in a string. Like say: print "He is %d tall." % height
-3
votes
1 answer

Assigning double values in C works unexpectedly

Ive tried reading a lot of problems on SO and yet I cant seem to understand why my program reacts so strange.. I have this simple code trying to Implement sqrt function: double sqrt,high,low,currNum; scanf("%lf",&sqrt); high = sqrt; low =…
Omri Shneor
  • 965
  • 3
  • 18
  • 34
-3
votes
1 answer

C/C++ Arithmetic expression with double numbers - strange results - translating in java

FIRST PROBLEM In C code I have this expression: double completeExpression = x1 - h*exp(-lambda*t); I have split it in two operations: double value = h*exp(-lambda*t); double subtraction = x1 - value; The problem is that subtraction is different…
michele
  • 26,348
  • 30
  • 111
  • 168