Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
int gcd(int a, int b); | ||
int main(int argc, const char *argv[]) | ||
{ | ||
int a,b; | ||
printf("Input to number e.g: 8 16\n"); | ||
scanf("%d %d",&a,&b); | ||
printf("最大公约数为: %d\n",gcd(a,b)); | ||
// 最小公倍数公式: |a x b| / gcd | ||
printf("最小公倍数为: %d\n",(abs(a)*abs(b))/gcd(a,b)); | ||
return 0; | ||
} | ||
/*辗转相除法求最大公约数*/ | ||
int gcd(int a, int b) | ||
{ | ||
int c; | ||
while (a != 0) { | ||
c = a; | ||
a = b % a; | ||
b = c; | ||
} | ||
return b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
float my_sqrt(float a); | ||
int main(int argc, const char *argv[]) | ||
{ | ||
float a; | ||
printf("Input the num to cal root: \n"); | ||
scanf("%f",&a); | ||
printf("%.0f 的平方根等于: %.2f\n",a,my_sqrt(a)); | ||
return 0; | ||
} | ||
/*迭代法求平方根*/ | ||
float my_sqrt(float a) | ||
{ | ||
float x0,x1; | ||
x0 = a / 2; | ||
x1 = (x0 + a / x0) / 2; | ||
while (fabs(x1 - x0) >= 1e-5) { | ||
x0 = x1; | ||
x1 = (x0 + a / x0) / 2; | ||
} | ||
return x1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import socket | ||
HOST = '127.0.0.1' | ||
PORT = 50009 | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.connect((HOST,PORT)) | ||
s.sendall('Hello,World') | ||
data = s.recv(1024) | ||
s.close() | ||
print 'Received', repr(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import socket | ||
HOST = '' | ||
PORT = 50009 | ||
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | ||
s.bind((HOST,PORT)) | ||
s.listen(1) | ||
conn, addr = s.accept() | ||
print 'Conneted by', addr | ||
while True: | ||
data = conn.recv(1024) | ||
if not data: | ||
break | ||
print data | ||
conn.sendall(data) | ||
conn.close() |