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
write a c program for swapping two strings using pointer
Is a house a shell structure?
What are integer variable, floating-point variable and character variable?
How many data structures are there in c?
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.
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
What type is sizeof?
What is #define used for in c?
What are terms in math?
What is wrong with this program statement? void = 10;
What are the types of macro formats?
How do you do dynamic memory allocation in C applications?
What is static memory allocation?