Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

C program to sort a list of numbers and to determine the median

YASH PAL, 31 July 2024

In this tutorial, we are going to write a C Program to sort a list of numbers and to determine the median in C Programming with practical program code and step-by-step full complete explanation.

C Program to sort a list of numbers and to determine the median

C Program to sort a list of numbers and to determine the median.

 
#include<stdio.h>
#include<conio.h>

#define N 10

void main()
{
    int i,j,n;
    float median,a[N],t;

    printf("Enter the number of itemsn");
    scanf("%d",&n);
    printf("Input %d valuesn",n);

    for(i=1;i<=n;i++)
        scanf("%f",&a[i]);

    for(i=1;i<=n-1;i++)
    {
        for(j=1;j<=n-1;j++)
        {
            if(a[j]<=a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
            else
                continue; 
        }
    }

    if(n%2==0)
        median=(a[n/2]+a[n/2+1])/2.0;
    else
        median=a[n/2+1];

    for(i=1;i<=n;i++)
        printf("%f",a[i]);

    printf("nMedian is %f",median);
}

Output

 
Enter the number of items
5
Input 5 values
1.111 2.222 3.333 4.444 5.555
5.555000 4.444000 3.333000 2.222000 1.111000
Median is 3.333000

Ente the number of items
6
Input 6 values
3 5 8 9 4 6

9.000000 8.000000 6.000000 5.000000 4.000000 3.000000
Median is 5.500000
c coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes