SORTING TECHNIQUES
Aim:
To write a program in C using pointer to sort the given the values in
ascending and descending order pass the values in array as arguments.
Algorithm:
1. Start the program.
2. Declare the array variable
3. Call the function get data, in which the scanf function is used to get the values.
4. Call the function shown, the array is passed as argument, sorting takes place.
5. Display the result.
6. Stop the program.
Program:
#include <stdio.h>
#define MAX 50
main()
{
int arr[MAX],n;
int getdata(int*,int);
void show(int* ,int);
n = getdata(arr,MAX);
show(arr,N);
}
int getdata(int*a, intn)
{
int x,i =0;
printf(”Enter the array elements one by one”);
whiie(i<n)
{
scanf(”%d”,&x)
(a+i) = x;
i + +;
void show(int* ,int);
n = getdata(arr,MAX);
show(arr,N);
}
int getdata(int*a, intn)
{
int x,i =0;
printf(”Enter the array elements one by one”);
whiie(i<n)
{
scanf(”%d”,&x)
(a+i) = x;
i + +;
}
return i;
}
void show(int*a,int n)
{
intl;
for(i=0; i<n; ++i)
{
if(a[i]>a[j])
{
}
printf(”%d”, *a(j));
}
Output
Enter the array elements one by one
17 16 9 4 3 27
17 16 9 4 3 27
3 4 9 16 17 27
Result:
0 comments:
Post a Comment