Switch Sign of a Number

In this lesson, we make use of the NOT operator to switch the sign of a number.

Introduction

In this question, we take input and switch its sign.

Problem Statement

We need to write a program to switch the sign of a number.

Input: 10
 
Output: -10

Solution

We already know that 2’s complement of any number gives a negative number with the formula below.

Formula

~x = ( ...

Access this course and 1400+ top-rated courses and projects.