fork download
  1. // C++ program to find the smallest number which greater than a given number
  2. // and has same set of digits as given number
  3. #include <iostream>
  4. #include <cstring>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. // Utility function to swap two digits
  9. void swap(char *a, char *b)
  10. {
  11. char temp = *a;
  12. *a = *b;
  13. *b = temp;
  14. }
  15.  
  16. // Given a number as a char array number[], this function finds the
  17. // next greater number. It modifies the same array to store the result
  18. void findNext(char number[], int n)
  19. {
  20. int i, j;
  21.  
  22. // I) Start from the right most digit and find the first digit that is
  23. // smaller than the digit next to it.
  24. for (i = n-1; i > 0; i--)
  25. if (number[i] > number[i-1])
  26. break;
  27.  
  28. // If no such digit is found, then all digits are in descending order
  29. // means there cannot be a greater number with same set of digits
  30. if (i==0)
  31. {
  32. cout << "Next number is not possible";
  33. return;
  34. }
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
210
2
compilation info
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty