answersLogoWhite

0

An array or vector of int or double or any other signed type can achieve this. If the array must alternate, then simply traverse the array alternating the signs as you go:

std::vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

bool sign=true; // true is positive.

for (int i=0; i<9; ++i)

{

if (sign) { // value must be positive

if (v[i]<0) v[i] *= -1; // if negative, make positive

} else { // value must be negative

if (0<v[i]) v[i] *= -1; // if positive, make negative

}

sign = !sign; // switch sign for next iteration

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Continue Learning about Engineering

Write a program in c that prompt user with following lines add two integers test an integer for odd or even and quit?

write a program in C that prompts the user with the following lines: a) Add two integers c) Compare two integers for the larger t) Test an integers for odd or even q) Quit


Writes a c program to find the sum of all integers between 1 and n?

Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11


What is a plus equals plus plus a - minus minus a?

You meana += ++a - --a?Well, it can be anything, depending on the compiler's decision. Never ever write expressions like this.


How do you write a program that accepts 5 integers in an array and shows the average of 3?

To write a program that accepts 5 integers in an array and calculates the average of the first three, you can follow these steps: First, create an array to hold the 5 integers. Then, prompt the user to input the integers and store them in the array. Finally, compute the average of the first three integers by summing them and dividing by 3, and display the result. Here’s a simple example in Python: numbers = [int(input(&quot;Enter integer {}: &quot;.format(i + 1))) for i in range(5)] average = sum(numbers[:3]) / 3 print(&quot;Average of the first three integers:&quot;, average)


Write a program with a loop that lets the user enter a series of integers the user should enter -99 to signal the end of the series after the program should display the largest and smallest.?

#include&lt;iostream.h&gt; #include&lt;conio.h&gt; main() { int i,j; i=0; j=0; for(i=1;i&lt;=5;i++) { if(i&gt;j){ cout&lt;"the value of i is="&lt;&lt;i; } else { cout&lt;&lt;"the value of j is="&lt;&lt;j; } } getch(); }