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 is meant by initialization and how we initialize a variable?
What are linked lists in c?
What is pointer to pointer in c with example?
Why can't I perform arithmetic on a void* pointer?
Why void main is used in c?
What is a program flowchart and how does it help in writing a program?
What is a dynamic array in c?
List some of the static data structures in C?
How can I do graphics in c?
List the difference between a While & Do While loops?
What is structure data type in c?
I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.
simple program of graphics and their output display
Explain what’s a signal? Explain what do I use signals for?
Explain what does it mean when a pointer is used in an if statement?