Friday, April 9, 2021

20.30. Write a program that reads an array and sort them.

#include<stdio.h>
#include<conio.h> 
#include<stdlib.h>
void main ()
{
int *a,i,j,temp,n;
printf("How many number: ");
scanf("%d", &n);
a=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%d",a+i);
for(i=n-1;i>0;i--)
for(j=0;j<i;j++)
if(*(a+j)>*(a+j+1))
{
temp=*(a+j);
*(a+j)=*(a+j+1);
*(a+j+1)=temp;
}
for(i=0;i<n;i++);
printf("%4d", * (a+i));
getch ();
}

No comments:

Post a Comment