Given 2 numbers a and b find the smallest number greater than b by interchanging the digits of a and if not possible print -1.
Answers
Answer:
/* Write a C' program .Input a and b .Find the smallest number greater than b by inter changing the digits of a and if not possible return -1 */
#include<stdio.h>
main()
{
int a, b,rev=0,d,return;
do
{
printf("Enter two numbers a and b \n");
scanf("%d %d", &a, &b)
}while(b<a);
while(a!=0)
{
d=a%10;
rev=(rev*10)+d;
a=a/10;
}
if(rev>b)
{
printf("%d is greater than %d \n", rev,b);
}
else if (rev==b)
{
print{"Both are equal \n");
}
else
{
return= -1;
printf("%d",return)
}
}
Answer:
#include<stdio.h>
main()
{
int a, b,rev=0,d,return;
do
{ printf("Enter two numbers a and b \n");
scanf("%d %d", &a, &b)
}while(b<a);
while(a!=0)
{ d=a%10;
rev=(rev*10)+d;
a=a/10;
}
if(rev>b)
{ printf("%d is greater than %d \n", rev,b);
}
else if (rev==b)
{ print{"Both are equal \n");
}
else
{ return= -1;
printf("%d",return)
}
}