I want to connect sketching and sketching

I want to connect sketching and sketching.
It does not work when I put it between simply.
Please tell me the connection of the sketching of A/B.

sketch A

#include <Servo.h>

Servo myservo;

int pos = 0;

void setup() {
myservo.attach( 2 );
}

void loop() {
for ( pos = 0; pos < 180; pos += 1 ) {
myservo.write( pos );
delay( 15 );
}
for ( pos = 180; pos > 0; pos -= 1 ) {
myservo.write( pos );
delay( 15 );
}
}


sketch B

int tonePin = 4; //Tone - Red Jumper
int trigPin = 9; //Trig - violet Jumper
int echoPin = 10; //Echo - yellow Jumper
int clockPin = 11; //IC Pin 11 - white Jumper
int latchPin = 12; //IC Pin 12 - Blue Jumper
int dataPin = 13; //IC Pin 14 - Green Jumper

byte possible_patterns[9] = {
B00000000,
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00111111,
B01111111,
B11111111,
};
int proximity=0;
int duration;
int distance;

void setup() {
//Serial Port
Serial.begin (9600);

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(tonePin, OUTPUT);
}

void loop() {
digitalWrite(latchPin, LOW);
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;

/if (distance >= 45 || distance <= 0){
Serial.println(“Out of range”);
}
else {
Serial.print(distance);
Serial.println(" cm");
}
/

proximity=map(distance, 0, 45, 8, 0);
//Serial.println(proximity);

if (proximity <= 0){
proximity=0;
}
else if (proximity >= 3 && proximity <= 4){
tone(tonePin, 200000, 200);
}
else if (proximity >= 5 && proximity <= 6){
tone(tonePin,5000, 200);
}
else if (proximity >= 7 && proximity <= 8){
tone(tonePin, 1000, 200);
}
shiftOut(dataPin, clockPin, MSBFIRST, possible_patterns[proximity]);
digitalWrite(latchPin, HIGH);

delay(600);
noTone(tonePin);
}

Please edit your post and use code tags for the code

type
** **[code]** **

past your code after that
type
** **[/code]** **

repeat for the second sketch

You can do a search for merge sketch

It does not work when I put it between simply.

"It does not work" does not mean anything. We can't see what you tried and we don't know which errors you get form the compiler (if any) or what you expect to happen and what actually happens (if it compiles).

Hints:
1)
There can only be one loop() function and one setup() function.
2)
Understand the sketches.
3)
If both sketches use the same pin for different purposes (e.g. input and output) you need to fix that up by changing the pin in one of the sketches during the merge.

Note:
I have never merged sketches; I try to understand what examples or sketches do and copy / paste the parts that I need.

This Simple Merge Demo may help.

...R