Sorting height of n number of students
Topics Covered:
- To stores name, age and height of n number of students and display them in proper format
- To sort 10 integer number in ascending order
- To sort 10 integer number in descending order
- Sorting height of n number of students
- Sorting height of 10 number of students
//to stores name, age and height of n number of students and display them in proper format
#include<conio.h>
#include<stdio.h>
int main()
{
int i,age[100],n;
float height[100];
char name[100][30];
//input section
printf(“enter the number of students\n”);
scanf(“%d”,&n);
for(i=0;i<=n-1;i++)
{
printf(“enter name\n”);
scanf(“%s”,&name[i]);
printf(“enter age\n”);
scanf(“%d”,&age[i]);
printf(“enter height\n”);
scanf(“%f”,&height[i]);
}
//output section
printf(“name\t age\t height\n”);
for(i=0;i<=n-1;i++)
{
printf(“%s\t%d\t%f\n”,name[i],age[i],height[i]);
}
return 0;
}
//to sort 10 integer number in ascending order
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[10],temp;
//input section
for(i=0;i<=9;i++)
{
printf(“enter numbers\n”);
scanf(“%d”,&a[i]);
}
//processing section
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//output section
for(i=0;i<=9;i++)
{
printf(“%d\t”,a[i]);
}
return 0;
}
//to sort 10 integer number in descending order
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[10],temp;
//input section
for(i=0;i<=9;i++)
{
printf(“enter number\n”);
scanf(“%d”,&a[i]);
}
//processing section
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//output section
for(i=0;i<=9;i++)
{
printf(“%d\t”,a[i]);
}
return 0;
}
//sorting height of n number of students
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,temp;
float h[10];
//input section
for(i=0;i<=9;i++)
{
printf(“enter height of students”);
scanf(“%f”,&h[i]);
}
//processing section
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(h[i]>h[j])
{
temp=h[i];
h[i]=h[j];
h[j]=temp;
}
}
}
//output section
for(i=0;i<=9;i++)
{
printf(“%.2f\t”,h[i]);
}
return 0;
}
//sorting height of 10 number of students
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j;
float h[10],temp;
//input section
for(i=0;i<=9;i++)
{
printf(“enter height of students”);
scanf(“%f”,&h[i]);
}
//processing section
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(h[i]>h[j])
{
temp=h[i];
h[i]=h[j];
h[j]=temp;
}
}
}
//output section
for(i=0;i<=9;i++)
{
printf(“%.2f\t”,h[i]);
}
return 0;
}