Questions tagged [negative-integer]
34 questions
-4
votes
3 answers
Our professor asked us to make a C program that will display the cube of a number using a while loop
When I input a negative integer the output will not result to it's cube value. I'm confused what should I do?
here is my code:
#include
int main()
{
int n, i, cube;
printf("Enter an integer: ");
scanf("%d",&n);
…

gigibot
- 3
- 1
-4
votes
1 answer
Why adding negative integers result in a positive integer on this C++ Program?
This program basically checks the two ends of a given interger sequence, adds the greatest of the two to R and changes the sign of the end we didn't choose. Repeats the process until there's only one number left (which is not add to R). The first…

Xggggg
- 1
- 1
-4
votes
3 answers
Ruby, making a number negative
This is probably super basic, but I've tried enough things that have failed to reach out..
I want to change a number to it's negative version.
answer = []
array = [3, 5, 2, 19, 2, 1]
array.each.with_index do |x, i|
if x > array[i+1]
…

Viola Crellin
- 61
- 2
- 8
-5
votes
2 answers
Ternary operation with a "negative" variable
What does the negative variable do in a ternary? Why is the output -10 is 10?
public class Ternary {
public static void main(String[] args) {
int i, k;
i = -10;
k = i < 0 ? -i : i;
System.out.print(i + " is " +…

Enrique_Iglesias
- 121
- 1
- 2
- 11