Again looking for some C-language topics about binary find and some of the various

Source: Internet
Author: User

First, let's explain binary find:

1. Take the middle value of a set of sequences with ascending (descending) order,

2. Then the comparison is made, and if the comparison equals the median, the return is not interpreted.

3. If it is less than the median, the look-up range becomes the right (left) edge.

4. If the value is greater than the median, the look-up is turned to the left (right) edge.

5. Until the left argument is greater than the right.

Find numeric #include <stdio.h>void swap (int v[],int a, int b) {              int temp;             temp = v[a];             v[a] = v[b];             v[b] = temp;} Void qsort (Int v[],int left, int right)     //wrote a quick Find method to sort {              int i,last;                     // There is an explanation in front of the blog              if (left >=  right)                          return;             swap (V,left, (left+right)/2);             last = left;              for (i = left +1;i <= right;i++)              {                          if (v[i] < v[ Left])                          swap (v,++last,i);             }            swap (V,left, Last);            qsort (v,left,last-1);             qsort (v,last+1,right);} Void bsearch (Int v[],int f,int l,int r); Int main () {int arry[10] =  {0};int find = 0;int i = 0;int left = 0,right =  sizeof (Arry)/sizeof (arry[0]);p rintf ("Enter a set of numbers (10):"); for (i=0 ;i < 10; i++) {scanf ("%d", &arry[i]);} printf ("Enter the number you want to find"); scanf ("%d", &find); Qsort (arry,left,right-1); Bsearch (arry,find,left,right); return 0;} Void bsearch (int v[],int find,int left,int right) {int mid = 0;if (left  >= right) {return ;} while (left <= right) {mid = (left + right)/2;if (v[mid] == find) {printf ("existence %d ", find); return ;} Else if (v[mid] < find) {left = mid +1;} Else if (v[mid] >  find) {right = mid -1;}} printf ("does not Exist");}


A substr realization, the title is such an Austrian:

Write a function that extracts a substring from a string. The function prototypes are as follows:

int substr (char dst[], char src[],int start, int len)

{}

The goal is to start by shifting the starting position of the SRC array backward from the start character to the maximum number of Len non-NUL characters to the DST array. After the copy is complete, the DST array must end with nul bytes. The return value of the function is the length of the string stored in the DST array.

PS: In fact, there are some requirements, but did not add:

//substr#include <stdio.h> #include  <string.h>int  substr (Char dst[],char src[],int start,int len); Int main () {char src[50]; char dst[20];int count;int start = 0,len = 0;printf ("Enter a string of characters"); scanf ("%s", &SRC);p rintf ("Enter starting value for Start"), scanf ("%d", &start);p rintf ("Please enter length intercept"), scanf ("%d", &len); count =  substr (Dst,src,start,len);p rintf ("%d", count); return 0;} Int substr (Char dst[],char src[],int start,int len) {int i,j,count;j =  0;count = 0;if (start < 0 | |   (Start+len)  > strlen (src)) {*dst =  ' return 0 ';p rintf ("Start point or length not conforming to rules"); for ( i = start-1;i < start + len-1;i++,j++) {if (src[i] ==  ') return 0;dst[j] = src[i];count++;} dst[j] =  ' + '; return count;} 

There is a fractional sequence

2/1+3/2+5/3+8/5+13/8+ ...

Find out the first 20 items of this series.

Denominator calculation # include <stdio.h>int main () {double Molecular,denominator,sum;int i;i = 0;sum =0;molecular = 2;denominator = 1;for (i = 0; i<20; i++) {int temp = molecular;sum + = (molecular/denominator); molecular + = Denominator;denominator = t EMP;} printf ("%f", sum); return 0;}

A ball from a 100-metre-high free fall, each landing after jumping back to the original height of half, then fall, and then rebound. Seeking the first

10 times when the landing, the total number of meters, the 10th time rebound how high.

Height calculation # include <stdio.h>int main () {double height = 100;int count;double sum = 0;for (count = 0;count < 10;count++) {sum + = Height;height/= 2;if (Count < 9) sum + = height;} printf ("%f%f", sum,height); return 0;}

The monkey eats the peach question. The monkey picked a few peaches on the first day, ate half immediately, and ate one more. The next morning he ate half of the remaining peaches and ate one more. After eating every day the last half of the rest of the first, to the 10th morning when you want to eat again, there is a peach. Ask how many peaches you picked on the first day.

Monkey eats peach include <stdio.h>int main () {int sum = 1;int Day = 0;for (Day=1, day < day++) {sum = (sum+1) * *;} printf ("%d", sum); return 0;}


This article is from the "egg-left" blog, please be sure to keep this source http://memory73.blog.51cto.com/10530560/1676801

Again looking for some C-language topics about binary find and some of the various

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.