Math, asked by yadavshivangi3011, 7 months ago

the opposite of -36 is 36 which is only integer that does not have opposite​

Answers

Answered by s1684aditi1507
1

Examples :

Input : num = 12345

Output : 54321

Input : num = 876

Output : 678

Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.

Flowchart:

ITERATIVE WAY

Algorithm:

Input: num

(1) Initialize rev_num = 0

(2) Loop while num > 0

(a) Multiply rev_num by 10 and add remainder of num

divide by 10 to rev_num

rev_num = rev_num*10 + num%10;

(b) Divide num by 10

(3) Return rev_num

Example:

num = 4562

rev_num = 0

rev_num = rev_num *10 + num%10 = 2

num = num/10 = 456

rev_num = rev_num *10 + num%10 = 20 + 6 = 26

num = num/10 = 45

rev_num = rev_num *10 + num%10 = 260 + 5 = 265

num = num/10 = 4

rev_num = rev_num *10 + num%10 = 265 + 4 = 2654

num = num/10 = 0

Program:

#include <bits/stdc++.h>

using namespace std;

/* Iterative function to reverse digits of num*/

int reversDigits(int num)

{

int rev_num = 0;

while(num > 0)

{

rev_num = rev_num*10 + num%10;

num = num/10;

}

return rev_num;

}

/*Driver program to test reversDigits*/

int main()

{

int num = 4562;

cout << "Reverse of no. is "

<< reversDigits(num);

getchar();

return 0;

}

Answered by gamerfromhellmehul69
2

Answer:

0 is the only integer which doesn't have opposite..

Similar questions