answersLogoWhite

0


Best Answer

#include

#include

void main()

{

int n ,i,j,temp,a[12]; //in a[] specify some number .

printf("Enter the no of inputs:");

scanf("%d", &n);

printf("Enter %d integer numbers :", n);

for(i=0;i

{

scanf("%d",&a[i]);

}

for (i=0;i

for(j=i+1;j

{

if(a[i]>a[j])

{

temp=a[j];

a[j]=a[i];

a[i]=temp;

}

}

printf("THE %d NUMBERS SORTED IN ASCENDING ORDER ARE :\n", n);

for(i=0;i

{

printf("%d ",a[i]);

}

getch();

}

Here is another version of the program. While the previous one is obviously simpler, this one is a good program to master the basics of pointer and array problems which might plague them at the beginning.

#include

#include

int a[100],i,j,k,n;

void sort(int *a,int n);

void swap(int *x,int *y);

main()

{

printf("How many numbers? ");

scanf("%d",&n);

printf("Enter the %d numbers separated from each other by a blank space: \n\n",n);

for (i=0;i

scanf("%d",&a[i]);

sort(a,n);

printf("\nThe numbers in descending order is: \n");

for (k=0;k

printf("\n%d",a[k]);

printf("\n\n");

}

void sort(int *a,int n)

{

int p=n-1;

while (p>=0)

{

for(i=0;i<=(p-1);++i)

{

if (a[i]<=a[i+1])

swap(&a[i],&a[i+1]);

else

continue;

}

--p;

}

}

void swap(int *x,int *y)

{

int t;

t=*x;

*x=*y;

*y=t;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

#include<iostream>

#include<algorithm>

void arrange (int* arr, const size_t size) {

std::sort (arr, arr+size);

}

int main () {

int a[8] {7, 19, 13, 2, 17, 5, 3, 11};

arrange (a, 8);

for (auto a : x) std::cout << x << ' ';

std::cout << std::endl;

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

template<class T>

void selection_sort (T a[], size_t size)

{

if (size<2)

return;

for (size_t left=0; left<size-1; ++left)

{

size_t selected=left;

for (size_t right=left+1; right<size; ++right)

if (a[right]<a[selected])

selected=right;

if (left!=selected)

{

T t = a[left];

a[left] = a[selected];

a[selected] = t;

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

// simple bubble sort - ellipses (...) used to indicate indentation for clarity

// an array - size 20 - could be anything

int a[20] = {1, 7, 5, 3, 7, 9, 67, 4, 20, 45, 76, 23, -1, -5, -8, 12, 67, 45, 23, 34 };

int swapflag = 1;

int i;

while (swapflag == 1) {

... swapflag = 0;

... for (i=0; i<19; i++)

... ... if (a[i] < a[i+1]) {

... ... ... swapflag = 1;

... ... ... a[i] ^= a[i+1];

... ... ... a[i+1] ^= a[i];

... ... ... a[i] ^= a[i];

... ... }

... }

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Computer programmers use an array to arrange digits of a number in ascending order. The program uses character array to store the digits and a quick sort feature to sort them.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Put the numbers in a vector and sort the vector. Then print it.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to arrange the digits of a number in ascending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program in java to enter 3 digits or more arrange the digits of the entered number in ascending order and display the result?

public static void main(String[] args) { int val = 100; int val1 = 50; System.out.println("Number of digits in " + val + " is: " + new String(val + "").length()); System.out.println("Number of digits in " + val1 + " is: " + new String(val1 + "").length()); }


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


What is a consecutive numbering method?

consecutive numbering method - A method in which consecutively numbered records are arranged in ascending number order - from the lowest number to the highest number.


How do you write a Java program to accept a 3-digits integer number and print out the highest digit from the derived input?

The tricky part is getting the individual digits. There are basically two ways to do this: 1) Convert the number to a string, and use string manipulation to get the individual digits. 2) Repeatedly divide the number by 10. The digit is the remainder (use the "%" operator). To actually get the highest digit, initially assume that the highest digit is zero (store this to a variable, called "maxDigit" or something similar). If you find a higher digit, replace maxDigit by that.


How a check digit is calculated?

Check digits are determined (or derived) by a set algorithm using the digits of the account number.

Related questions

Write a program in java to enter 3 digits or more arrange the digits of the entered number in ascending order and display the result?

public static void main(String[] args) { int val = 100; int val1 = 50; System.out.println("Number of digits in " + val + " is: " + new String(val + "").length()); System.out.println("Number of digits in " + val1 + " is: " + new String(val1 + "").length()); }


Smallest number you can using 91764?

The smallest number that someone can get using the 91764 digits is 14679. The secret is to arrange the digits from the least number to their greatest number.


How to find the smallest number?

When you are given some numbers just arrange them in ascending order and you will the smallest number which can be made out of those given numbers.


How do you work out the median for a set of eight numbers?

Arrange the numbers in ascending order, and then take the mean of the fourth and fifth number.


How do you arrange the digitsof a particular number to make the smallest and largest possible number?

To give the particular number the largest possible value, arrange the digits in the order of their individual value, beginning with the largest one on the left and smallest on the right. To give the particular number its smallest possible value, arrange the digits in the order of their individual value, beginning with the smallest one on the left and largest on the right.


How many such digits are there in the number 5831649 each of which is as far away from the beginning of the number as when the digits are rearranged in ascending order?

5831649 1345689 The 9 and the 6 are in the same position in both numbers.


Output for ascending order and descending order?

Example 7, 30, 11, 27, 9, 16,Ascending Order = 7, 9, 11, 16, 27, 30 ( You simply arrange the number from lowest to highest number )Descending Order = 30, 27, 16, 11, 9, 7 ( You simply arrange the number from highest to lowest number )


What is the biggest number you can make out of the following 3 digits 479?

You arrange the numbers from highest to lowest, so the answer is 974.


What is a four digit number with ascending digits whose first two numbers have a difference of two the third digit is even and the sum of the first three digits equal the last digit?

1348.


What is the smallest number you can make using the digits 1 2 3 4 5 and 6?

123,456 would be the smallest number using all 6 digits. You arrange the numbers from lowest to highest.


What is the median of 72 83 77 76 74 80 and 81?

After we put these digits in the ascending order that is : 72,74,76,77,80,81,83 The total digits are 7 therefore the middle number that is 77 will be the median. As pairs of 3 digits are formed on both sides of it.


Arrange the digits 112233 as a 6-digit numberIn this 6-digit number the 1's are separated by 1 digitthe 2's by 2 digits and the 3's by 3 digits?

312132 or 231213