C Program to Sort a random array of n integers using Quick sort algorithm | DS - IProgramX

Q.  Sort a random array of n integers (accept the value of n from user) in ascending order by using recursive Quick sort algorithm.


Program

#include <stdio.h>
int main()
{
  int n, array[1000], c, d, t;

  printf("Enter number of elements\n");
  scanf("%d", &n);

  printf("Enter %d integers\n", n);

  for (c = 0; c < n; c++) {
    scanf("%d", &array[c]);
  }

  for (c = 1 ; c <= n - 1; c++) {
    d = c;

    while ( d > 0 && array[d-1] > array[d]) {
      t          = array[d];
      array[d]   = array[d-1];
      array[d-1] = t;

      d--;
    }
  }

  printf("Sorted list in ascending order:\n");

  for (c = 0; c <= n - 1; c++) {
    printf("%d\n", array[c]);
  }

  return 0;
}

Output:

Enter number of elements
5
Enter 5 integers
5
7
9
3
6
Sorted list in ascending order:
3
5
6
7
9

Post a Comment

3 Comments

  1. py --version

    py -m pip --version

    python --version

    py -m pip install pandas matplotlib seaborn

    ReplyDelete
  2. EXPERIMENT 1: STUDY OF DATA SCIENCE TOOLS

    Aim: To study and explain the basic tools used in Data Science.

    1. Python
    - A high-level, general-purpose programming language used for data analysis, machine learning and automation.
    - Libraries: NumPy (numerical computing), Pandas (data manipulation), Matplotlib/Seaborn (visualization), Scikit-learn (machine learning).

    2. Jupyter Notebook
    - An open-source, web-based environment for writing and running Python code in cells.
    - Combines code, output, charts and formatted text in one notebook.
    - Used for exploratory data analysis and prototyping.

    3. Microsoft Excel
    - A spreadsheet application for storing tabular data, calculations and charts.
    - Common features: SUM, AVERAGE, VLOOKUP and PivotTables.
    - Useful for data entry, cleaning and quick reporting.

    4. Tableau
    - A data visualization and business intelligence tool.
    - Provides drag-and-drop interactive charts and dashboards with little or no coding.
    - Helps communicate insights visually.

    Conclusion: Excel is useful for quick tabular work, Python/Jupyter for programmatic analysis and modelling, and Tableau for interactive visual reporting.

    Note: Experiment 1 is a study/theory practical in the lab manual; it does not require a Python program.

    ReplyDelete
  3. Aim: To study and explain the basic tools used in Data Science: Python, Jupyter Notebook, Microsoft Excel and Tableau.

    Objective: To understand the features, purpose and applications of commonly used Data Science tools.
    1. Introduction
    Data Science is a field that uses programming, statistics and analytical techniques to extract useful information from data. Different tools are used for data processing, analysis and visualization.
    2. Python
    Python is a high-level, general-purpose programming language widely used in Data Science, Data Analytics and Machine Learning.

    Features:
    - Simple and easy-to-learn syntax.
    - Free and open-source.
    - Supports data analysis and visualization.
    - Provides many useful libraries.
    Important Python Libraries:
    Library Purpose
    NumPy Numerical calculations
    Pandas Data manipulation
    Matplotlib Creating graphs
    Seaborn Statistical visualization
    Scikit-learn Machine Learning

    Applications: Data cleaning, statistical analysis, visualization and prediction.
    3. Jupyter Notebook
    Jupyter Notebook is an open-source, web-based interactive environment used to write and execute Python code in separate cells.

    Features:
    - Executes code cell by cell.
    - Displays output immediately.
    - Supports graphs, tables and Markdown.
    - Useful for data analysis and experimentation.
    Applications: Exploratory Data Analysis, Machine Learning and statistical analysis.
    4. Microsoft Excel
    Microsoft Excel is a spreadsheet application used to store, organize, calculate and analyse data in rows and columns.

    Features:
    - Stores data in tabular format.
    - Provides formulas and functions.
    - Supports sorting and filtering.
    - Creates charts and PivotTables.
    Important Functions:
    Function Purpose
    SUM() Calculates total
    AVERAGE() Calculates average
    COUNT() Counts values
    MAX() Finds highest value
    MIN() Finds lowest value
    VLOOKUP() Searches for data

    Applications: Data entry, financial calculations, employee analysis and report preparation.
    5. Tableau
    Tableau is a Business Intelligence and data visualization tool used to create interactive dashboards and reports.

    Features:
    - Drag-and-drop interface.
    - Connects to different data sources.
    - Creates interactive dashboards.
    - Supports charts, graphs and maps.
    - Helps identify patterns and trends.
    Applications: Sales analysis, business reporting, customer analysis and decision-making.
    6. Comparison of Data Science Tools
    Tool Main Purpose
    Python Programming and data analysis
    Jupyter Notebook Interactive code execution
    Excel Spreadsheet operations
    Tableau Data visualization and dashboards

    7. Conclusion
    Python, Jupyter Notebook, Excel and Tableau are important tools in Data Science. Python is used for programming and analysis, Jupyter Notebook provides an interactive coding environment, Excel is useful for spreadsheet operations, and Tableau helps create interactive dashboards. Together, these tools help analyse data and make better decisions.

    ReplyDelete