1. Reverse the contents of a one-dimensional array
#include <stdio.h>
void func (int *s,int N)
{
int i,temp;
for (i=0;i<n/2;i++)
{
Temp=s[i];
S[i]=s[n-1-i];
S[n-1-i]=temp;
}
}
void Main ()
{
int i,a[10];
for (i=0;i<10;i++)
A[i]=i;
Func (a,10);
for (i=0;i<10;i++)
printf ("%d\n", A[i]);
}
2. Array traversal
#include <stdio.h>
#define N 5
int search (int *s,int x)//s[n]
{
int i;
for (i=0;i<n;i++) if (s[i]==x) break;
if (i<n) return 1;
else return 0;
}
void Main ()
{
int a[n],i,e;
printf ("Enter the array:\n");
for (i=0;i<n;i++) scanf ("%d", &a[i]);
printf ("Enter the element:\n");
scanf ("%d", &e);
if (search (a,e) ==1) printf ("The element%d exists in the array.\n", e);
else printf ("Can not find the element%d.\n", e);
}
3. Sorting arrays By Selection method
#include <stdio.h>
#define N 6
void Sele_sort (int *s,int N)
{
int i,j,p,t;
for (i=0;i<1;i++)
{
P=i;
for (j=i+1;j<n;j++)
if (S[j]<s[p])
P=j;
T=S[P];
S[p]=s[i];
s[i]=t;
}
}
void Main ()
{
int a[n],i;
printf ("Enter the array:\n");
for (i=0;i<n;i++) scanf ("%d", &a[i]);
Sele_sort (A,n);
printf ("The sorted array:\n");
for (i=0;i<6;i++) printf ("%d", a[i]);
printf ("\ n");
}
4.
Examples of C language textbooks