C Language 9th time assignment

Source: Internet
Author: User

1. Write the function to determine whether the character entered by the user is a symmetric string (that is, a string that is the same as the Read and rewind). For example, "Xyzyx" and "Xyzzyx" are symmetrical.

#include <stdio.h>intMain () {Charstr[ -]; intI=0, A,b,j,k;      Gets (str);  while(str[i]!=' /') I++; if(i%2==0) {a=i/2-1; b=i/2; }      Else{a=i/2-1; b=i/2+1; }       for(j=a,k=b;j>=0, K<=i;j--, k++)       {            if(str[j]!=Str[k]) Break; }      if(k==i+1) printf ("yes\n"); Elseprintf ("no.\n");} 

2. The write function uses the bubbling sort method to sort the number of entries (or student names) entered by the user in ascending order.

#include <stdio.h>#include<string.h>voidF1 () {Chara[ -]; intlength,j,i,temp; printf ("Please enter:"); scanf ("%s", a); Length=strlen (a);  for(j=0; j<length;j++)    {         for(i=length-1;i>0; i--)        {            if(a[i]<a[i-1]) {temp=A[i]; A[i]=a[i-1]; A[i-1]=temp; }}} printf ("sort it in ascending order:");  for(i=0; i<length;i++) printf ("%c", A[i]); }intMain () {F1 (); return 0;}

3. Write the function use the Select Sort method to sort the number of entries (or student names) entered by the user in ascending order.

#include <stdio.h>intMaxinta[]) {    inti,j,t;  for(i=0;i<Ten; i++)     for(j=i+1;j<Ten; j + +)    if(a[i]>A[j]) {T=A[i]; A[i]=A[j]; A[J]=T; }}intMain () {inta[Ten],i; printf ("Enter a 10 number:");  for(i=0;i<Ten; i++) scanf ("%d",&A[i]);     Max (a);  for(i=0;i<Ten; i++) printf ("%d", A[i]); return 0; }

4. Write the function to sort the number of entries (or student names) entered by the user in ascending order using the insertion sort method.

#include <stdio.h>intMain () {inta[ -]; inti,temp,j; printf ("Please enter:"); scanf ("%d", a);  for(i=1;i< -; i++) {Temp=A[i]; J=i-1;  while(j>=0&&temp<A[j]) {A[j*1]=A[j]; J--; } a[j*1]=temp} printf ("Sort Ascending to:")}

I did my best, really.

C Language 9th time assignment

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.