Close Menu
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
  • Home
  • Notes
    • Online Courses
      • 12th Class
      • 11th Class
      • 10th Class
      • 9th Class
  • Jobs
    • PPSC Jobs
    • SPSC Jobs
    • Punjab Police Jobs
  • Education News
  • E-Books
    • Punjab Text Book (PTB)
  • Model Papers
  • Results
  • Admissions
  • Colleges
  • More
    • Paper Schemes
    • Date Sheets
    • Guess Papers
    • Roll No Slips
Facebook X (Twitter)
Trending
  • NADRA Islamabad Announced Latest April Jobs 2024
  • TEVTA Sargodha Announced Instructor / Clerk Jobs 2024
  • BPSC Announced Latest Jobs Through Advertisement no. 03/2024
  • All Subjects 12th Class Paper Scheme 2024 | Punjab Board
  • 12th Class Computer Science Paper Scheme 2024 Punjab Board
  • 9th Class Pakistan Studies Guess Papers 2024 Punjab Board
  • 12th Class Biology Paper Pairing Scheme 2024 Punjab Board
  • Physics 12th Class Paper Scheme 2024 Punjab Board
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
  • Home
  • Notes
    • Online Courses
      • 12th Class
      • 11th Class
      • 10th Class
      • 9th Class
  • Jobs
    • PPSC Jobs
    • SPSC Jobs
    • Punjab Police Jobs
  • Education News
  • E-Books
    • Punjab Text Book (PTB)
  • Model Papers
  • Results
  • Admissions
  • Colleges
  • More
    • Paper Schemes
    • Date Sheets
    • Guess Papers
    • Roll No Slips
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
Home » Computer Science » C Language » C Programs » [C/C++] Program to Sort Array – Bubble Sorting
C Language

[C/C++] Program to Sort Array – Bubble Sorting

March 22, 2015Updated:September 13, 2018No Comments2 Mins Read
WhatsApp Facebook Twitter Pinterest LinkedIn Tumblr Email

C/C++ code to arrange number in ascending or descending order using bubble sorting algorithm. In bubble sorting 1st element is compared with 2nd element and then swapped. Similarly 2nd with 3rd and then 3rd with 4th and so on.. Unless the array is sorted.

C Code

#include <stdio.h>
 
int main()
{
  int array[100], temp, n;
 
  printf("Enter number of elements\n");
  scanf("%d", &n);
 
  printf("Enter %d integers\n", n);
 
  for (int i = 0; i < n; i++)
    scanf("%d", &array[i]);
 
  for (int i = 0 ; i < ( n - 1 ); i++)
  {
    for (int j = 0 ; j < n - c - 1; j++)
    {
      if (array[j] > array[j+1]) 
      {
        temp       = array[j];
        array[j]   = array[j+1];
        array[j+1] = temp;
      }
    }
  }
 
  printf("Sorted list in ascending order:\n");
 
  for ( int i=0 ; i < n ; i++ )
     printf("%d\n", array[i]);
 
  return 0;
}

C++ Code

#include <iostream>

using namespace std;
 
int main()
{
  int array[100], temp, n;
 
  cout <<"Enter number of elements\n";
  scin >> n;
 
  cout << "Enter %d integers\n";
 
  for (int i = 0; i < n; i++)
    cin >> array[i];
 
  for (int i = 0 ; i < ( n - 1 ); i++)
  {
    for (int j = 0 ; j < n - c - 1; j++)
    {
      if (array[j] > array[j+1]) 
      {
        temp       = array[j];
        array[j]   = array[j+1];
        array[j+1] = temp;
      }
    }
  }
 
  cout << "Sorted list in ascending order:\n";
 
  for ( int i=0 ; i < n ; i++ )
     cout << array[i];
 
  return 0;
}

 

c programs computer science 2nd year cpp programs Online Course
Share. WhatsApp Facebook Twitter Pinterest LinkedIn Tumblr Email
Khurram Farooq
  • Website
  • Facebook
  • X (Twitter)

I'm a full-stack developer, specializing in the PHP, JS, Wordpress, MEAN Stack, MERN Stack & Django. I hold a high standard of quality in everything that I do.

Related Posts

How to do Exponents in Java – 3 Different Methods

January 12, 2020

Different Types of Processors And Their Features

January 12, 2020

Biology 1st Year Guess Paper 2018 Punjab Board

May 28, 2018
Leave A Reply Cancel Reply

SEARCH
ADVERTISEMENT
STAY WITH US
  • Facebook
  • Twitter
  • Instagram
LATEST JOBS

NADRA Islamabad Announced Latest April Jobs 2024

April 4, 2024

TEVTA Sargodha Announced Instructor / Clerk Jobs 2024

April 4, 2024

BPSC Announced Latest Jobs Through Advertisement no. 03/2024

April 4, 2024
LATEST NOTES

All Subjects 12th Class Paper Scheme 2024 | Punjab Board

April 4, 2024

12th Class Computer Science Paper Scheme 2024 Punjab Board

April 4, 2024

9th Class Pakistan Studies Guess Papers 2024 Punjab Board

April 4, 2024
RECENT POSTS

NADRA Islamabad Announced Latest April Jobs 2024

April 4, 2024

TEVTA Sargodha Announced Instructor / Clerk Jobs 2024

April 4, 2024

BPSC Announced Latest Jobs Through Advertisement no. 03/2024

April 4, 2024

All Subjects 12th Class Paper Scheme 2024 | Punjab Board

April 4, 2024
TRENDING THIS WEEK

PEC SBA 2023 Model Paper for Grades 03-08 [Download PDF]

December 16, 2022

Notification Regarding the Revised Standard Pay packages for Project (PPS) Posts

August 4, 2022

KU Announces Online BA/MA & B.COM Degree Programs 2023

July 27, 2023
ABOUT US
ABOUT US

Notes, Guess Papers, Old Papers, Jobs, Admissions, Results, Datasheets and everything else that falls into the wide world of education & careers. For any assist and query please contact us.

Home · About Us · Team · Contact · Advertise · DMCA Policy · Cookies Policy · Privacy Policy
© 2013-2026 Powered By FScOnline - Made with ♥ for the students of Pakistan.

Type above and press Enter to search. Press Esc to cancel.

Go to mobile version
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.