072. Write a program to accept a number n from user and then accept n array elements from user, print these array elements in ascending and descending order in C language

#include<stdio.h>
#include<conio.h>
main()
{
	int n,i,a[20],j,max,min,temp;
	clrscr();
	printf("Enter number : ");
	scanf("%d",&n);
	printf("Enter array elements...\n");
	for(i=0;i<n;i++)
	{
	printf("Enter element %d : ",i+1);
		scanf("%d",&a[i]);
	}
	max=a[0];
	for(i=0;i<n;i++)
	{
		for(j=0;j<i;j++)
			if(a[i]>a[j])
			{
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
	}
	printf("Ascending order.....\n");
	for(i=0;i<n;i++)
	{
		printf(" %d  ",a[i]);
	}
 
	min=a[0];
	for(i=0;i<n;i++)
	{
		for(j=0;j<i;j++)
			if(a[i]<a[j])
			{
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
	}
	printf("\nDescending order....\n");
	for(i=0;i<n;i++)
	{
		printf(" %d  ",a[i]);
	}
 
	getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *