Title Description
The size of any two adjacent elements in array a differs by 1, and is given the array A and target integer t to find the position of T in array A.
Thinking of solving problems
For the target T, start with the current position A[index] comparison, the next possible position is index = ABS (T-a[index]), because to find all the positions, so find out the first subscript position, and then from the next beginning of the subscript to re-find.
Code Implementation
#include <stdio.h>#include <stdlib.h>#include <math.h>intFind_num (intA[],intNintNumber) {int Index;inti =0;Index=ABS(number-a[0]);if(N <0)return-1; while(Index< n) {if(a[Index] = = number) {printf("%d ",Index);Index+=ABS(number-a[Index+1]);Continue; }Else Index+=ABS(number-a[Index]); }return-1;}intMainintARGC, Char const*ARGV[]){intA[] = {4,5,6,5,6,7,8,9,Ten,9};intn = sizeof (a)/sizeof (a[0]); Find_num (A,n,5);return 0;}
"Face question"-the size of any two adjacent elements in array a differs by 1 to find out the position of a number in array a. (All locations)