c program to arrange digits in a no in ascending and
descending order
Answer / 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 |
What is the difference between pure virtual function and virtual function?
Explain the difference between struct and union.
Program to swap the any two elements in an array containing N number of elements?
1 Answers Bosch, Glenwood, Ugam Solutions,
Explain what is wrong with this program statement? Void = 10;
What is main void in c?
void main() { int i=5; printf("%d",i++ + ++i); }
What are control structures? What are the different types?
Explain how can I write functions that take a variable number of arguments?
Explain how do you search data in a data file using random access method?
What is chain pointer in c?
Why is main function so important?
What are the basic data types associated with c?