Home > Back-end >  change the signs in the number field
change the signs in the number field

Time:12-07

I have a problem, I need to change the signs in the number field. I don't know how to do it. Thank you for your help


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
   }
}
}
}


CodePudding user response:

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];
}
  •  Tags:  
  • c
  • Related