c program to arrange digits in a no in ascending and
descending order



c program to arrange digits in a no in ascending and descending order..

Answer / chand

#include <stdio.h>

int main() {
int num,i=0,size=0,j,temp;
scanf("%d",&num);
int k=num;
while(num>0)
{
int rem;
rem=num%10;
size++;
num/=10;
}
int arr[size];
while(k>0)
{
int rem1;
rem1=k%10;
arr[i]=rem1;
i++;
k/=10;
}
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}

}
}
for(i=0;i<size;i++)
{
printf("%d ",arr[i]);
}
return 0;
}

Is This Answer Correct ?    22 Yes 7 No

Post New Answer

More C Interview Questions

Can we use visual studio for c?

0 Answers  


When is a null pointer used?

0 Answers  


21. #define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

3 Answers  


How will you find a duplicate number in a array without negating the nos ?

0 Answers  


hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .

0 Answers   Aegis, CDAC, Infosys,






What is openmp in c?

0 Answers  


What is volatile in c language?

2 Answers   HCL, TCS,


Is null a keyword in c?

0 Answers  


find the output of the following program main() { int x=5, *p; p=&x; printf("%d",++*p); }

10 Answers   Amdocs, TCS,


how to write palindrome program?

3 Answers  


How can I determine whether a machines byte order is big-endian or little-endian?

0 Answers  


int main() { int i=-1,j=-1;k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d%d%d%d%d",i,j,k,l,m); }

3 Answers   HCL,


Categories