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
What are the advantages of using linked list for tree construction?
can anyone please tell about the nested interrupts?
What is calloc()?
What is void main () in c?
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
How can I read in an object file and jump to locations in it?
What is a ternary operator in c?
What do you mean by c what are the main characteristics of c language?
What is volatile variable how do you declare it?
Differentiate between new and malloc(), delete and free() ?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
How do you convert strings to numbers in C?
Tell me what is the purpose of 'register' keyword in c language?
What are the benefits of organizational structure?
Explain what is the advantage of a random access file?