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

Haskell : List of anonymous functions using lambda expressions

i am quite new to Haskell and i want to define a list of anonymous functions using lambda expressions, which represent the four basic arithmetic operations. this is what i have done bao = (\ x y -> x+y) but i want to apply 3 more expressions(\x y…
John
  • 135
  • 6
-2
votes
1 answer

Use Awk to sum all cells in a csv

I have a bunch of csv files, each is an 84 x 84 matrix of numbers. I'm trying to use awk to sum all of the cells (to generate a single number). So far all I've been able to come up with is the following, which can sum a single column at a time (for…
BennyD
  • 55
  • 7
-2
votes
1 answer

Logical operators in if and scope of floating point

I have 2 float variables var_a and var_b I want to execute a program if both of them are greater than zero. I used the following snippet code if(var_a > 0 and var_b > 0) execute() It shows an error: invalid syntax. I also wanted to check if…
-2
votes
2 answers

A program to evaluate arithmetic expression

Here's an interesting problem I haven't managed to deal with yet. Given an arithmetic expression in Reverse Polish Notation, write a program to evaluate it. The expression is given as a list of numbers and operands. For example [5, 3, '+'] should…
treskov
  • 328
  • 1
  • 4
  • 17
-2
votes
3 answers

Building an exponent calculator

I'm relatively new to programming in C#. I'm building an exponent calculator, and I got it working, but while debugging I came across an issue that I do not understand why I get the output that I get. This is the class and method in question when I…
ajdawg
  • 17
  • 1
-2
votes
2 answers

Brace initialization of a double using an expression?

I'm not used to using brace initialization, but I figured I'd start porting my code over since it's been in the standard since c++11. One question arises: Is the following expression correct? double MyFunction(double a,double b,int c) { double…
-2
votes
1 answer

Arithmetic operations on string value

I am trying Calculator code and design link https://i.stack.imgur.com/KrzRD.png If my input = 2 * 4 + 6 - 10 / 2 entered in EDIT TEXT How can i perform arithmetic operations on below part of my code??? buttonEqual.setOnClickListener(new…
shyam
  • 1,084
  • 12
  • 20
-2
votes
1 answer

Getting Artihmetic Exception Error

I wrote this program. But I am getting Arithmetic Exception Error. Program: #include using namespace std; int fact(int n) { int facte = 1; for (int i = 1; i <= n; i++) facte *= i; return facte; } int main() { …
-2
votes
2 answers

CMacro and integer arithmetic

I need to implement something like this but using CMacro: int a = //some constant; int x = //constant int c = //constant int y = a*x+b; I've tried something like: #define A 3 #define X 6 #define B 8 #define Y ((A)*(X) + (B)) However if I use the…
user8469759
  • 2,522
  • 6
  • 26
  • 50
-2
votes
2 answers

Haskell + division

Im able to sum the zth element of all of the tuples but for some weird reason I only get 1 after dividing my result by 2. averageYear :: [(String, String, Int)] -> Int averageYear [] = 0 averageYear ((x,y,z):xs) = (z + (averageYear xs)) `div`…
ajanakos
  • 99
  • 1
  • 9
-2
votes
2 answers

How to Solve this arithmetic c++

I have and array with some elements like 5, 3, 7 and an initial int A (eg 5 in first case). I have to do addition and subtraction on this number from the array elements to get the maximum number less than or equal to M (10 in this case). The…
Aman
  • 17
  • 3
-2
votes
1 answer

how can i save values with arithmetic operators in mysql with php?

I have a field datatype VARCHAR in mysql. It has to save data like 495/1,495/2 but when i am running query from PHP it save in mysql like 495, 247.5. so basically mysql divides the values. Then I have tried this $sfno = $_POST['sfno']; // i am…
Jaiffable
  • 67
  • 1
  • 12
-2
votes
1 answer

Postfix and prefix operators in C and Java producing different results

I thought basic arithmetic operators had same precedence in most languages. But for the following code snippet- int a = 5; a = --a + a++; //print a C copiler (GNU GCC) gives me result as 9 where as in java I get 8. What's going on? According to me…
-2
votes
3 answers

Reduce three lines of arithmetic to one line? Divide and round

I have an integer value which will always be a whole number, called $post_count I want to divide $post_count by 2. So if it's an even number, it will always produce a whole result. E.g if $post_count = 8 then I want the result of my arithmetic to be…
Francesca
  • 26,842
  • 28
  • 90
  • 153
-2
votes
1 answer

Reverse Polish Notation in Haskell

I need to write a function that takes an arithmetic expression and converts it to a string in Reverse Polish notation using Haskell. Creating a function to evaluate an RPN expression is quite easy and need not to worry about, it's only the…
lehal475
  • 1
  • 2