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

What is the Difference between Macro and ordinary definition?

3 Answers   Bosch, Cognizant, College School Exams Tests, Motorola,


write a C code To reverse a linked list

2 Answers   Motorola, Wipro,


Why doesnt this code work?

0 Answers  


Where we use clrscr in c?

0 Answers  


What are the advantages of using macro in c language?

0 Answers  






What does it mean when a pointer is used in an if statement?

0 Answers  


What is dynamic memory allocation?

0 Answers  


Can we access the array using a pointer in c language?

0 Answers  


While compiling a c program,graphics header files are not including in my program..eg: <graphics.h>,what may be the problem...is there any environment settings exists.

2 Answers  


Explain what are multibyte characters?

0 Answers  


What are the types of type specifiers?

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

5 Answers   TCS, Vimukti Technologies,


Categories