Examples of C language textbooks

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.