This C Program an integral input and evaluates a number which is greater than the entered number, which also uses the same digits.

Here is a source code of the C program to find a greater number of entered number using same digits. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program that takes input as 2323 and gives output as 2332.`

`* ie.the new number should be greater than the previous number`

`* but should have the same digits`

`*/`

`#include <stdio.h>`

`#include <math.h>`

int evaluate(int [], int);

int find(int);

int main()

`{`

int num, result;

printf("Enter a number: ");

scanf("%d", &num);

result = find(num);

if (result)

`{`

printf("The number greater than %d and made of same digits is %d.\n", num, result);

`}`

`else`

`{`

printf("No higher value possible. Either all numbers are same or the digits of the numbers entered are in decreasing order.\n");

`}`

return 0;

`}`

int find(int num)

`{`

int digit[20];

int i = 0, len = 0, n, temp;

n = num;

while (n != 0)

`{`

digit[i] = n % 10;

n = n / 10;

`i++;`

`}`

len = i;

for (i = 0; i < len - 1; i++)

`{`

if (digit[i] > digit[i + 1])

`{`

temp = digit[i];

digit[i] = digit[i + 1];

digit[i + 1] = temp;

return (evaluate(digit, len));

`}`

`}`

return 0;

`}`

int evaluate(int digit[], int len)

`{`

int i, num = 0;

for (i = 0; i < len; i++)

`{`

num += digit[i] * pow(10, i);

`}`

return num;

`}`

$ gcc greaternum.c -lm $ ./a.out Enter a number: 56732 The number greater than 56732 and made of same digits is 57632.

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at programming examples on all topics, go to C Programming Examples.