noNAme
noNAme

Reputation: 15

change the signs in the number field

How to change the signs in the number field?

void swap_sign(const int size, int array[]) {
  if (array[] != NULL) {
    for (int i = 0; i < size; i++) {
      if (array[i] == /* - */ ) {
        //turn the sign to + and save to the field
      } else if (array[i] == /* + */ ) {
        //turn the sign to - and save to the field
      }
    }
  }
}

Upvotes: 0

Views: 50

Answers (1)

Deepak
Deepak

Reputation: 2742

Not sure why you have commented things out in the for loop, but switching signs is achieved with just multiplying the minus sign.

array[i] = -array[i];

for(int i=0; i < size; i++){
   array[i] = -array[i];
}

Upvotes: 1

Related Questions