Questions tagged [integer-arithmetic]

Anything related to integer arithmetic, i.e. arithmetic operations on integer numbers. This is mostly relevant for languages which represent integer numbers with specific data-types (e.g. `int` or `long` in C, C++ or Java).

Anything related to integer arithmetic, i.e. arithmetic operations on integer numbers. This is mostly relevant for languages which represent integer numbers with specific data-types (e.g. int or long in C, C++ or Java).

452 questions
-1
votes
3 answers

In bash how to use the last argument- and adding all other arguments to array

I have a script where the user can add as many arguments as he would like (numbers). The script will sum all the numbers beside the last number - The last number (argument) is the number that I need to divide by For example: ./test.sh 2 2 6 5 This…
dzbeda
  • 173
  • 2
  • 9
-1
votes
2 answers

Integer Arithmetics Going Wild

Please, could somebody explain what's happening under the hood there? The example runs on an Intel machine. Would the behavior be the same on other architectures? Actually, I have a hardware counter which overruns every now and then, and I have to…
-1
votes
3 answers

Get the sum of all carried digits while performing addition on 2 or more integers

I've got this task, which I honestly don't understand what exactly to do. It my be because of my English level, or mathmatics level, but this is really something I can not make sense of. Could you help be at least to understand the task ? My php…
-1
votes
2 answers

Bash Scripting, Reading From A File

I'm trying to select lines that have F starting them from my .txt file, and then find the average of the numbers, here's my code, I don't know why it's not adding up. #!/bin/bash function F1() { count=1; total=0; file='users.txt' while read line;…
mia
  • 3
  • 1
  • 3
-1
votes
1 answer

Why "may be rounded" from int to float, but "can be preserved" from int to double?

Computer Systems: a Programmer's Perspective says: When casting values between int, float, and double formats, the program changes the numeric values and the bit representations as follows (assuming data type int is 32 bits): From int to float,…
Tim
  • 1
  • 141
  • 372
  • 590
-1
votes
1 answer

Algorithm for determine "direction of movement" in a finite field

I am trying to determine the most efficient mechanism for determining direction of movement (i.e., shortest direction between an initial starting value and a second ending value) within a finite field (i.e., a numeric field of integers mod M). For…
Jeffrey P
  • 431
  • 1
  • 4
  • 14
-1
votes
1 answer

"Primitive Calculator" - Problem with creating division loop

I am trying to create a calculator that uses loops instead of the '*' or '/' operators. I am having problems in computing the result within my division loop below that takes in two positive numbers as input. How can I compute the accurate…
101001
  • 113
  • 9
-1
votes
1 answer

integer arithmetic inside printf()

New to C programming. Why the output of this code below is not 0 20 0 but instead it is 1 20 0? printf ( "\n%d %d %d", x != 1, x = 20, x < 30 ) ; My understanding is that the code is assigning x to a value other than 1 (1=true therefore != true is…
-1
votes
1 answer

User-input values in first column with squares displayed in second column for multi-dimensional arrays

A small help is needed regarding multi-dimensional arrays in C language. I am trying to compute square of each value, entered by user. However, I want both the value and results displayed as output. I am looking for something like in this format for…
SalN85
  • 445
  • 3
  • 12
-1
votes
2 answers

How does "str" - "str" in C work? How are they stored?

Disclaimer: This question asks how "str literal" + "str literal" works For how 'a' + 'b' or '9' - '0' = 9 ('character' + 'character') works : Why does subtracting '0' in C result in the number that the char is representing? C character values…
cdpp
  • 152
  • 2
  • 9
-1
votes
2 answers

How to determine "Number" data type from arbitrary "String" inputs

I have tried to search a lot about it but couldn't come to a concrete solution. I am developing a rest service (using Jax-RS) for which 3 Number inputs are provided, but for each input, the actual data type is unknown at compile time. e.g; "num1"…
iTech
  • 81
  • 4
-1
votes
1 answer

Addition in perl one-liner

I'm trying to add 1000 to numbers with a perl one liner. Here is what I tried: perl -pi -e "s/ZZZ(\d+)ZZZ/ZZZ\1+1000ZZZ/e" file.txt I was hoping that would add 1000 to numbers between ZZZ. But I get the error message: Backslash found where operator…
-1
votes
1 answer

Inconsistency with Large Number Subtraction

I'm relatively new to C++, and I'm attempting to create a set of arithmetic functions that are able to handle large numbers, using a struct called biggie that handles the numbers like a string. I'm currently having difficulty with the subtract…
JaredCubilla
  • 538
  • 1
  • 8
  • 24
-1
votes
3 answers

Assign variables value to a variable

Using the command line, I've defined two variables set a = 5 set b = 5 In addition I've set another variable, c, in which I am trying to assign a's and b's value. I tried - set c = $($a+$b) But I've got Illegal variable name. I tried - set c c =…
Alex Goft
  • 1,114
  • 1
  • 11
  • 23
-1
votes
2 answers

Is there any formula for number of divisors of a*b?

Let a and b be two numbers, Number of divisors of (a) =n1; Number of divisors of (b) =n2; how to find the number of divisors of (a*b) by using n1 and n2? a=15; b=20 n1=4; //no of divisors of a n2=6; //no of divisors of b ans=(a*b);…
sridhar3525
  • 49
  • 1
  • 11