The 11th Time lab work

Source: Internet
Author: User

First question

#include <stdio.h> void sort (int a[],int n); int main () {    int n,a[8];    int i;        printf ("Enter N (n<=8):");    scanf ("%d", &n);    printf ("Enter a[%d]:", n);    for (i=0;i<n;i++)    scanf ("%d", &a[i]);    Sort (a,n);    printf ("After sorted,a[%d]=", N);    for (i=0;i<n;i++)    printf ("%3d", A[i]);            return 0;} void sort (int a[],int n) {    int i,j,t;    for (i=1;i<n;i++) for    (j=0;j<n-i;j++)    if (a[j]>a[j+1])    {     t=a[j];     A[J]=A[J+1];     a[j+1]=t;}     }

Second question

#include <stdio.h>int search (int list[],int n,int x); int main () {    int n,x,list[10];    int i;        printf ("Input N:");    scanf ("%d", &n);    printf ("Input%d integers:", n);    for (i=0;i<n;i++)    scanf ("%d", &list[i]);    printf ("Input x:");    scanf ("%d", &x);    Search (list,n,x);    if (search (list,n,x)!=-1)    printf ("mid=%d\n", Search (list,n,x));    else    printf (" -1\n");        return 0;} int search (int list[],int n,int x) {    int i;    for (i=0;i<n;i++)    {    if (X==list[i])    return i;    else    return-1;    }        }

Third question

#include <stdio.h>int main (void) {    int count,i,m,n,no;    int num[50];    int *p;    printf ("Enter n,m:");    scanf ("%d%d", &n,&m);    for (i=0;i<n;i++)    num[i]=i+1;    P=num;    count=no=0;    while (no<n-1)    {    if (*p!=0) count++;    if (count==m)        {         no++;         printf ("Exit person%d:%d\n", no,*p);         *p=0;         count=0;        }        p++;        if (p==num+n)        p=num;    }    P=num;    while (*p==0)    p++;    printf ("Last Person:%d\n", *p);        }

The last question does not, ask the classmate, but still did not understand, intends to attend class listens to the teacher to speak.

The 11th Time lab work

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.