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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

write a c program for swapping two strings using pointer

2063


Is a house a shell structure?

674


What are integer variable, floating-point variable and character variable?

575


How many data structures are there in c?

591


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1471






Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2092


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3706


typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1041


What type is sizeof?

565


What is #define used for in c?

590


What are terms in math?

561


What is wrong with this program statement? void = 10;

783


What are the types of macro formats?

584


How do you do dynamic memory allocation in C applications?

611


What is static memory allocation?

584