Questions tagged [negative-number]

A negative number is a number that is less than 0. It is signified by a preceding hyphen (i.e. -12,345).

This tag should be used for any questions dealing specifically with negative numbers.

599 questions
-1
votes
3 answers

Negative sign swapping in a python list

x = [[-123 456],[567 -8910],[432 -890], [-567 976]] I have a list of list, I want to swap the negative symbol of x and y elements of a list, if x is not negative it should be changed into negative and if y is negative it should be changed into…
devopio
  • 15
  • 3
-1
votes
1 answer

transform a positive number to a negative number

I want to display a number as negative using a minus sign: 5000 --> - 5000
Remise 5,000 TND
This is my essay…
H_Hmd
  • 25
  • 8
-1
votes
1 answer

Javascript: why indexOf function returns -1 when the element exist in the array?

I have created a matrix like: u = Array.from({ length: 100}, (v, i) => []); console.log(u) Then, after running the code and filling the matrix. I wanted to get the index of the minimum element in particular row.so the result should be either 0…
nora
  • 27
  • 2
-1
votes
2 answers

Print only non-negative balance in Java

I'm currently solving the PaymentCard exercise in https://java-programming.mooc.fi/part-4/1-introduction-to-object-oriented-programming and the output of this program should not be a negative balance. If ever the balance gets negative, it will not…
bimyou
  • 21
  • 1
  • 5
-1
votes
2 answers

How to raise an exception when a list contains negative values

I want calculate the harmonic mean and raise an exception if my list "x" contains negative values. But the code is not working. How can I adjust my for + if statement to fix the problem? Thanks. x=[1,2,3.0,-3,,-2,1] def hmean(x): sum= 0.0 for i…
hblanc28
  • 29
  • 5
-1
votes
1 answer

Stop value going into negative in javascript

I have a function where you can click to like, and you kan also click to dislike. How can I make it NOT possible to go to negative number, so that if you click dislike after 0 it stays 0? function stem(id) { var antal_stemmer =…
-1
votes
4 answers

why python len() command for "-1" is 2?

for any negative number, it also counts the "-" as a character even though its a part of that number. I tried to make my numbers string first but it won't change the outcome, it always gives +1 to the actual amount of characters involved. code : def…
HARD YOLO
  • 11
  • 1
-1
votes
1 answer

Pickup Sticks Game: Program outputs a negative number where it is supposed to stop

I have made a code for a game of pickup sticks that can be played in two modes: Single Player (against the computer) Multiplayer (local game) I seem to be having a problem with the program in the single-player mode. The computer outputs…
-1
votes
1 answer

How to tell if a hexadecimal number is negative?

My question is: Is there a definite system that says that if the first bit (when we turn our hexadecimal number to binary) is a 1 then the hexadecimal number is negative? Is this a definite rule for the computer that the first bit always defines if…
-1
votes
5 answers

Check if a Negative number falls within a range

I have a code which reads the temperature values constantly and temperature values will be always negative. How do I write a If condition in C# to check if this temperature falls with in a range of -44 and -46. I tried with the below code and still…
Baba
  • 49
  • 1
  • 8
-1
votes
2 answers

Python - Why scatter of matplotlib plots points which have negative coordinates, with positive coordinates?

so there is a big trouble in my script : I have done an array with numpy with contains x,y and z coordinates of some points. some of these points have negative coordinates (for x and/or y and/or z). And for reasons I don't understand, when I use the…
Yoann Pageaud
  • 412
  • 5
  • 22
-1
votes
6 answers

im trying to find biggest negative number in array c#

Running perfect but there is no result only cursor. The expected result is -15 int[] dizi = { 4, 5, -15, 22, -34, 3, 0, 7, 43, 100 }; int maxNumber = 0; for (int i = 0; i < dizi.Length; i++) { if…
-1
votes
2 answers

Trying to generate random array of integers, getting the same list each run. C++

Why does this result in the same array every time i run it? int arr[100]; for (int i = 0; i < 100; i++) { arr[i] = rand() % 11 + (-5); }
BenW
  • 737
  • 10
  • 41
-1
votes
1 answer

PYTHON 3.0 Negative numbers aren't working as inputs

I'm trying to make a factoring program, but it doesn't seem to work with negative number a-, b- and c-inputs. from fractions import gcd factor = -1 opp = 0 number = 1 success = 0 a = int(input("a-value: ")) b = int(input("b-value: ")) c =…
richzli
  • 131
  • 8
-1
votes
4 answers

Negative Integers >Positive Integers?

In this code, -20 should be the min since its negative and the farthest from zero correct? But when I run MinAlgoritm, the integer 5 is printed out. I have a Max version of this that works fine but this doesn't. How can this be? Are there any…
user5108713