#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; }
#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;
}
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;
}
}
}
// 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];
... ... }
... }
}
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.
Put the numbers in a vector and sort the vector. Then print it.
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()); }
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.
consecutive numbering method - A method in which consecutively numbered records are arranged in ascending number order - from the lowest number to the highest number.
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.
Check digits are determined (or derived) by a set algorithm using the digits of the account number.
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()); }
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.
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.
Arrange the numbers in ascending order, and then take the mean of the fourth and fifth 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.
5831649 1345689 The 9 and the 6 are in the same position in both numbers.
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 )
You arrange the numbers from highest to lowest, so the answer is 974.
1348.
123,456 would be the smallest number using all 6 digits. You arrange the numbers from lowest to highest.
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.
312132 or 231213