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

In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

764


What are multidimensional arrays?

656


What are the types of variables in c?

581


What is the condition that is applied with ?: Operator?

663


Is array a primitive data type in c?

579






How can I split up a string into whitespace-separated fields?

571


explain what is an endless loop?

611


What is the usage of the pointer in c?

606


How can you access memory located at a certain address?

667


What are pointers? What are different types of pointers?

630


Explain how can you tell whether two strings are the same?

582


What is an array in c?

596


What is c preprocessor mean?

793


For what purpose null pointer used?

606


What is sorting in c plus plus?

565