Write a program to sort an 1-d array in ascending order.

1 Answer

Answer :

#include<iostream.h>

#include<conio.h>

void main()

{

int arr[20];

int i, j, temp,n;

clrscr();

cout<<"\n Enter the array size:";

cin>>n;

cout<<"\n Enter array elements:";

for(i=0;i<n;i++)

{

 cin>>arr[i];

}

for(i=0;i<n;i++)

{

 for(j=i+1;j<n;j++)

{

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

{

 temp=arr[i];

 arr[i]=arr[j];

 arr[j]=temp;

 }

}

}

cout<<”Sorted Array:”;

for(i=0;i<n;i++)

{

 cout<<”\n”<<arr[i];

}

getch();

}


Related questions

Description : Write a program to sort elements of an array in ascending order.

Last Answer : #include #include void main() { int a[5],i,j,temp; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Which of the following algorithms sort n integers, having the range 0 to (n2 -1), in ascending order in O(n) time ? (A) Selection sort (B) Bubble sort (C) Radix sort (D) Insertion sort

Last Answer : (C) Radix sort

Description : Write a program to create two threads. One thread will display the numbers from 1 to 50 (ascending order) and other thread will display numbers from 50 to 1 (descending order).

Last Answer : class Ascending extends Thread {  public void run() {  for(int i=1; i<=15;i++) {  System.out.println("Ascending Thread : " + i);  } } } class Descending extends Thread { ... a=new Ascending(); a.start(); Descending d=new Descending(); d.start(); } }

Description : Write a program to declare a class ‘book’ containing data members as ‘title’, ‘author-name’, ‘publication’, ‘price’. Accept and display the information for one object using pointer to that object.

Last Answer : #include<iostream.h> #include<conio.h> class book { char author_name[20]; char title[20]; char publication[20]; float price; public: void Accept(); void Display(); }; void ... title \t author_name \t publication \t price\n ; p-> Display(); getch(); }

Description : Write a program that copies contents of one file into another file.

Last Answer : Assuming input file to be copied file1.txt contents are “Hello Friends…” and file where the contents need to copy is file2.txt already created  #include #include #include #include #include void main() { clrscr(); ifstream fs; ofstream ft; char ch, fname1[20], fname2[20]; cout

Description : Write a program to implement the following hierarchy using suitable member functions. Refer Figure No.2.

Last Answer : # include <iostream.h> #include<conio.h> class Student { int roll_no; char name[10]; public: void read_studentData() { cout<< Enter student s roll no and name \n ; cin> ... { result r; clrscr(); r.read_result(); r.display_result(); getch(); }

Description : Write a program to overload the ‘—’ unary operator to negate the values.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class Number { int x,y; public: Number (int a, int b) { a =x; b =y; } void display() { cout<< ... ; -N1; cout<<"\n After negation:"; N1. display (); getch (); }

Description : Write a program to count the number of lines in file.

Last Answer : #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { ifstream file; char ch; int n=0; clrscr(); file.open("abc.txt"); while(file) { file. ... \n Number of lines in a file are:"<<n; file.close(); getch(); }

Description : Write a program to implement single inheritance from the following Refer Figure No.1

Last Answer : #include #include class employee { protected: int emp_id; char name[10]; }; class emp_info:public employee { int basic_salary; public: void getdata() { coutemp_id; coutname; coutbasic_salary; } void putdata() { cout

Description : How can you sort the elements of the array in descending order?

Last Answer : By calling Sort() and then Reverse() methods. 

Description : How can you sort the elements of the array in descending order? 

Last Answer : By calling Sort() and then Reverse() methods.

Description : Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].

Last Answer : quicksort ((data + 222), 100)

Description : Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

Last Answer : Mergesort always makes recursive calls to sort subarrays that are about half size of the original array, resulting in O(n log n) time.

Description : If the given input array is sorted or nearly sorted, which of the following algorithm gives the best performance? a) Insertion sort b) Selection sort c) Quick sort d) Merge sort

Last Answer : a) Insertion sort

Description : Write the applications of object oriented programming.

Last Answer : Applications of object oriented programming are: 1) Real time systems 2) Simulation and modeling 3) Object-oriented databases 4) Hypertext, hypermedia and expertext 5) AI and expert systems ... and parallel programming 7) Decision support and office automation systems 8) CIM/CAM/CAD systems

Description : Write any four benefits of OOP. 

Last Answer : Benefits of OOP: 1. We can eliminate redundant code and extend the use of existing classes. 2. We can build programs from the standard working modules that communicate with one another, ... interface descriptions with external systems much simpler. 10. Software complexity can be easily managed.

Description : Write two properties of static member function

Last Answer : i) A static member function can have access to only other static data members and functions declared in the same class. ii) A static member function can be called using the class name with a scope resolution operator instead of object name as follows: class_name::function_name;

Description : Write a numPy program to create a numPy array with all values as True printed 10 times. -Technology

Last Answer : This answer was deleted by our moderators...

Description : Accept data for five students and display it. Write a C++ program to displya sum of array elements of array size n. 

Last Answer : #include<iostream.h> #include<conio.h> void main() { int arr[20],i,n,sum=0; clrscr(); cout<<"\nEnter size of an array:"; cin>>n; cout<<"\nEnter ... ; } cout<<"\nSum of array elements is:"<<sum; getch(); }

Description : Write a C++ program to accept array of five elements, find and display smallest number from an array.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[5],smallest,i; clrscr(); cout<<" Enter array elements:"; for(i=0;i<5;i++) cin>>a[i] ... } } cout<<endl<<"Smallest number="<<smallest; getch(); }

Description : Write a program to compute the sum of all elements stored in an array using pointers.

Last Answer : #include #include void main() { int a[5],sum=0,i,*ptr; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Write a program to search a number from an array using pointer to array.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[5],i,*a1,no,flag=1; clrscr(); a1=&a[0]; cout<<"\nEnter array elements :"<<endl; for(i=0;i<5 ... =0) { cout<<"\n\t Number is not present.... "; } getch(); }

Description : Write a program in C++ to search an element from an array using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[10], n, i,*p, flag=0, x; clrscr(); cout<<"Enter no. of array elements \n"; cin>>n; cout<< ... } if(flag==0) cout<<x<<"is not found \n"; getch(); }

Description : If the median of data (arranged in ascending order) 31, 33, 35, x, x+10, 48, 48, 50 is 40, then find value of x. -Maths 9th

Last Answer : Given data is 31, 33, 35, x, x+10, 48, 48, 50 Number of observation = 8 (even) Median = Value of (8/2)th observation + Value of (8/2+1)th observation / 2 Value of 4th observation + Value of 5th observation / 2 = x + x + 10 / 2 = x + 5 ∴ x + 5 = 40 ⇒ x = 35

Description : Ten observations 6, 14, 15, 17, x + 1, 2x – 13, 30, 32, 34, 43 are written in ascending order. -Maths 9th

Last Answer : Here, the arranged data is 6, 14, 15, 17, x + 1, 2x - 13, 30, 32, 34, 43 Total number of observations = 10 Here, 10 is an even number , therefore median will be the mean of (10 / 2)th and (10 / 2 + 1)th observation. ... ⇒ 3x + 12 / 2 = 24 ⇒ 3x - 12 = 48 ⇒ 3x = 60 ⇒ x = 20 ∴ The value of x = 20

Description : If the median of data (arranged in ascending order) 31, 33, 35, x, x+10, 48, 48, 50 is 40, then find value of x. -Maths 9th

Last Answer : Given data is 31, 33, 35, x, x+10, 48, 48, 50 Number of observation = 8 (even) Median = Value of (8/2)th observation + Value of (8/2+1)th observation / 2 Value of 4th observation + Value of 5th observation / 2 = x + x + 10 / 2 = x + 5 ∴ x + 5 = 40 ⇒ x = 35

Description : Ten observations 6, 14, 15, 17, x + 1, 2x – 13, 30, 32, 34, 43 are written in ascending order. -Maths 9th

Last Answer : Here, the arranged data is 6, 14, 15, 17, x + 1, 2x - 13, 30, 32, 34, 43 Total number of observations = 10 Here, 10 is an even number , therefore median will be the mean of (10 / 2)th and (10 / 2 + 1)th observation. ... ⇒ 3x + 12 / 2 = 24 ⇒ 3x - 12 = 48 ⇒ 3x = 60 ⇒ x = 20 ∴ The value of x = 20

Description : A bag contains 30 tickets numbered from 1 to 30. Five tickets are drawn at random and arranged in ascending order -Maths 9th

Last Answer : Total number of ways in which 5 tickets can be drawn = n(S) = 30C5. The tickets are arranged in the form T1, T2, T3 (= 20), T4, T5 Where T1, T2 ∈{1, 2, 3, , 19} and T4, T5 ∈{21, 22, , 30 ... {10 imes9}{2}\) x \(rac{5 imes4 imes3 imes2 imes1}{30 imes29 imes28 imes27 imes26}\) = \(rac{285}{5278}.\)

Description : Arrange the following options in ascending order of their BOD value: 1. Sample of highly polluted pond water. 2. Sample from unpolluted pond water. 3.

Last Answer : Arrange the following options in ascending order of their BOD value: 1. Sample of highly polluted pond water. 2. Sample ... -b-a C. c-a-b D. a-c-b

Description : Which of the following ratios are in ascending order?

Last Answer : Which of the following ratios are in ascending order? A. `5:6,11:13,8:9,7:8` B. `5:6,7:8,11:13,8:9` C. `11:13,5:6,7:8,8:9` D. `5:6,11:13,7:8,8:9`

Description : What Factors of 76 in ascending order?

Last Answer : 1,2,4,8,12,18,48

Description : What Factors of 76 in ascending order?

Last Answer : 1,2,4,8,12,18,48

Description : Which one of the following sequences in the ascending order of their geographical size is correct? [CDS 2003] (a) Bihar - Chhattisgarh - Jharkhand - Orissa (b) Jharkhand - West Bengal - Tamil Nadu ... West Bengal - Bihar - Chhattisgarh - Tamil Nadu (d) Chhattisgrah - Jharkhand - Tamil Nadu - Orissa

Last Answer : Ans: (b)

Description : In the modern periodic table, the elements are arranged in the ascending order of their

Last Answer : atomic number.

Description : Which of the following is the correct arrangement of the given metals in ascending order of their reactivity? Zinc, Iron, Magnesium, Sodium A) Zinc > Iron > Magnesium > Sodium B) Sodium > Magnesium > Iron > Zinc C) Sodium > Zinc > Magnesium > Iron D) sodium > Magnesium > Zinc > Iron

Last Answer : D) sodium > Magnesium > Zinc > Iron

Description : The master list of an indexed file A. is sortedin ascending order B. containsonly a list of keys and record numbers C. has a number assigned toeach record D. both (b)and (c) E. None of the above

Last Answer : has a number assigned toeach record

Description : The ascending order of a data hierarchy is: a) Bit - Bytes - Field - Record - File - Database b) Bit - Bytes - Record - Field - File - Database c) Bytes - Bit - Record - Field - File - Database d) None of The Above

Last Answer : a) Bit - Bytes - Field - Record - File - Database

Description : Arrange the following devices in ascending order of the speed: A. RAM B. Hard disk C. Cache D. Floppy 1) ABDC 2) BDAC 3) DBAC 4) BADC

Last Answer : 3) DBAC

Description : Arrange the following primitive data types in an ascending order of their size: (i) char (ii) byte (iii) double (iv) int

Last Answer : Ans. The sizes of the given data types are as follows char = 2 bytes byte = 1 byte double = 8 bytes int = 4 bytes Arranging them in ascending order gives byte < char < int < double

Description : In time-cost optimization of a project, crashing is done. (A) On all the activities (B) On all the activities lying on the critical path (C) Only on activities lying on the ... critical activities and those that become critical at any stage of crashing in the order of ascending cost slope

Last Answer : D

Description : The ascending order or a data Hierarchy is a. bit - bytes - fields - record - file - database b. bit - bytes - record - field - file - database c. bytes - bit- field - record - file - database d. bytes -bit - record - field - file - database

Last Answer : a. bit - bytes - fields - record - file - database

Description : Select the answer that lists the units of bytes in ascending order (from smallest to largest) A. gigabyte, megabyte, terabyte B. megabyte, terabyte, kilobyte C. gigabyte, terabyte, megabyte D. kilobyte, gigabyte, terabyte

Last Answer : A. gigabyte, megabyte, terabyte

Description : Ingredients on a food label are listed in ____ order, based on weight. a. descending c. alphabetical b. ascending d. chronological

Last Answer : a. descending

Description : The odd numbers from 1 to 45 which are exactly divisible by 3 are arranged in an ascending order. The number at 6 th position is (A) 18 (B) 24 (C) 33 (D) 36

Last Answer : Answer: C

Description : Which of the following is in the ascending order of Data hierarchy? (1) Byte–Bit–File–Record–Database–Field (2) Field–Byte–Bit–Record–File– Database (3) Bit–Byte–Record–Field–Database–File (4) Bit–Byte–Field–Record–File– Database

Last Answer : Bit–Byte–Field–Record–File– Database

Description : In a pocket of A, the ratio of Rs.1 coins, 50p coins and 25p coins can be expressed by three consecutive odd prime numbers that are in ascending order. The total value of coins in the bag is Rs 58. If the number of Rs.1 ... of coins in the pocket of A? A) Rs 68 B) Rs 43 C) Rs 75 D) Rs 82 E) NONE

Last Answer : Answer: D  Since the ratio of the number of Rs. 1, 50p and 25p coins can be represented by 3 consecutive odd numbers that are prime in ascending order, the only possibility for the ratio is 3:5:7. Let the number of ... =100 7k+50 5k+25 3k=1025k (In above we find the value of k). ⇒ 8200p = Rs 82.

Description : What is the correct sequence of the following materials in ascending order of their resistivity ?  1. Iron  2. Silver  3. Constantan  4. Mica  5. Aluminium  Select the correct answer using the codes given below :  (a) 2, 5, 1, 3 ... 5, 3, 1 and 2  (c) 2, 3, 1, 5 and 4  (d) 4, 5, 1, 3 and 2

Last Answer : What is the correct sequence of the following materials in ascending order of their resistivity ?  1. Iron  2. Silver  3. Constantan  4. Mica  5. Aluminium  Select the correct answer using the codes given below :  ... 1 and 2  (c) 2, 3, 1, 5 and 4  (d) 4, 5, 1, 3 and 2

Description : The band gap of elements arranged in ascending order is : a. Diamond, Ge, Si b. Si, Ge, Diamond c. Ge, Si, Diamond d. Diamond, Si, Ge

Last Answer : answer is b