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
}
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
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
You meana += ++a - --a?Well, it can be anything, depending on the compiler's decision. Never ever write expressions like this.
#include<iostream.h> #include<conio.h> main() { int i,j; i=0; j=0; for(i=1;i<=5;i++) { if(i>j){ cout<"the value of i is="<<i; } else { cout<<"the value of j is="<<j; } } getch(); }
write a program to print the series 1/12+1/22+.........+1/n2 ?
5,000,000
You could write it as 5555555555555/1.
1/4
-6 / 1
54
They are: 42/200 = 0.21
-318 Negatives are integers.
-- write the difference between the integers without regard to their signs -- give the difference the same sign as the larger of the two integers
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
16 divided by 45
Yes, please do.
0.573 = 573/1000