A Program to Find Max & Min Elements with their Positions in a Given Array and then Sort the Above Array

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10],b[10],i,j,n,large,small,pos1=1,pos2=1,temp;
clrscr();
printf("Enter how many values u want:");
scanf("%d",&n);
printf("Enter elements into array a:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
large=small=a[0];
/* for(i=0;i<n;i++)
{
if(a[i]>large)
{
large=a[i];
pos1=i+1;
}
else if(a[i]<small)
{
small=a[i];
pos2=i+1;
}
}
printf("\nthe largest element is:%d\tpos=%d",large,pos1);
printf("\nthe small element is:%d\tpos=%d",small,pos2); */
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\the sorting order is given below:");
for(i=0;i<n;i++)
printf("%d",a[i]);
getch();
}

No comments:

Post a Comment

Copyright © EduRAR @ www.edurar.blogspot.in