1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
777dan777 [17]
3 years ago
11

Write a program in C++ to implement bubblesort using the swap function ?

Computers and Technology
1 answer:
marishachu [46]3 years ago
3 0

C++ program for implementation of Bubble sort  

#include <bits/stdc++.h>  

using namespace std;  

 void swap(int *x, int *y)  /*Defining Swap function of void return type*/

{  

  int temp = *x;  //Swaping the values  

   *x = *y;  

   *y = temp;  

}  

void bubbleSort(int array[], int n) /*Defining function to implement bubbleSort  */

{  

  int i, j;  

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

      for (j = 0; j < n-i-1; j++)  /*The last i components are already in location  */

      if (array[j] > array[j+1])  

          swap(&array[j], &array[j+1]);  //Calling swap function

}  

int main()  //driver function

{  

   int array[] = {3, 16, 7, 2, 56, 67, 8}; //Input array  

   int n = sizeof(array)/sizeof(array[0]);  //Finding size of array

   bubbleSort(array, n); //Function calling  

   cout<<"Sorted array: \n";  

   for (int i = 0; i < n; i++)  //printing the sorted array

       cout << array[i] << " ";  

   cout << endl;  

 return 0;  

}  

<u>Output</u>

Sorted array:  

2 3 7 8 16 56 67

You might be interested in
................. are used to summarize data (option) (a) report (b) action ​
Tems11 [23]
I think it A I feel like report is right for the answer
5 0
3 years ago
Read 2 more answers
How to cheat on asseeprep
Burka [1]
Just do it just look up the answers mate
6 0
2 years ago
In cell M2, enter a formula using a nested IF function as follows to determine first if a student has already been elected to of
aleksley [76]

Answer:

Following are the code to this question:

code:

=IF(EXACT(I2,"Yes"),"Elected",IF(EXACT(K2,"Yes"),"Yes","No"))

Explanation:

In the given the data is not defined so we explain only  the above code, but before that, we briefly define working of if the function that can be defined as follows:

  • The If() function, is used only when one of the logical functions and its value must return the value true. or we can say it only return a true value.
  • In the above function, a column "Elected" is used that uses other column values to check this column value is equal if this condition is true it will return "yes" value.

8 0
2 years ago
Write a short program using Python that will:
Alexxx [7]

Answer:

// program in Python to check perfect number

#function to find number is perfect or not

def is_Perfect_Number(n):

   #total variable

   tot = 1

   i = 2

   #sum of all divisor of number

   while i*i<=n:

       if n%i==0:

           tot = tot + i + n/i

       if tot == n and n != 1:

           return 1

       i = i+1  

   return 0

#read until user enter a perfect number

while True:

   #read integer

   num = int(input("Input an integer: "))

   #call the function

   if(is_Perfect_Number(num)):

       print(num,"is perfect number")

       #if perfect number break

       break

   else:

       print(num,"is not a perfect number")

       #ask again

   print("try again.")

Explanation:

Read number from user and then call the function is_Perfect_Number() with  parameter "num".This will find the sum of all divisor of number.If sum is  equal to number then it will return 1 else return 0.If the number is not  perfect then it will again ask to enter a number until user enter a perfect  number.

Output:

Input an integer: 24

24 is not a perfect number                                                                                                

try again.                                                                                                                

Input an integer: 28                                                                                                      

28 is perfect number

6 0
3 years ago
Answer the questions given below, share your ideas.Use the space for your answer.
Bess [88]

Answer:

I would get rid of the machine and well

8 0
2 years ago
Other questions:
  • Write a program for playing tic tac toe. Two players take turns marking an available cell in a 3 X 3 grid with their respective
    15·1 answer
  • True or false: although the first personal computers were available as early as the 1970's, the creation of the world wide web (
    11·1 answer
  • What type of lights are necessary for silhouettes?
    12·2 answers
  • What systemctl command configures a unit to start the next time the computer boots?
    10·1 answer
  • pWhat macOS system application tracks each block on a volume to determine which blocks are in use and which ones are available t
    14·1 answer
  • Which email client feature allows you to store the names and information of people you contact frequently?
    5·1 answer
  • Sales representatives want to capture custom feedback record details related to each Account. The sales reps want to accomplish
    12·1 answer
  • Question:
    14·1 answer
  • Which quality should an experiment have to be replicable and valid? O clearly detailed results O a well-cited research paper O s
    7·1 answer
  • A machine that converts energy to useful work.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!