\documentclass{ctexart}
\usepackage{amsmath}
\usepackage[hmargin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{
shapes.geometric,   %几何形状
calc,               %计算
positioning         %用于定位
}
\tikzset{
every picture/.style={
>=latex,
node distance=5mm and 5mm
%有无and的区别见手册positioning部分
}}

%定义框形状
\tikzstyle{SS}      %开始结束
=[rounded corners, draw]
\tikzstyle{IO}      %输入输出
=[trapezium, trapezium left angle=70, trapezium right angle=110, draw]
\tikzstyle{NR}      %内容
=[draw]
\tikzstyle{PD}      %判断
=[diamond, aspect=4, draw, inner sep=1.5pt]

\begin{document}


\begin{tikzpicture}[->]
%放框
\node[SS](start){开始};
\node[IO, below=of start](in){输入$N$};
\node[NR, below=of in](n1){$k=1$, $S=0$};
\node[NR, below=of n1](n2){$S=S+\dfrac1{k(k+1)}$};
\node[NR, right=of n2](n3){$k=k+1$};
\node[PD, below=of n2](pd){$k<N$};
\node[IO, below=of pd](out){输出$S$};
\node[SS, below=of out](stop){结束};
%连线
\path
(start) edge (in)
(in) edge (n1)
(n1) edge (n2)
(n2) edge (pd)
(pd) edge node[right]{否}(out)
(out) edge (stop);
\draw (pd.east)node[below]{是} -| (n3);
\draw (n3) |- ($(n1.south)!0.5!(n2.north)$);
\end{tikzpicture}
%
%
\begin{tikzpicture}[->]
\node[SS](start){开始};
\node[NR, below=of start](n1){$a=1$};
\node[NR, below right=1mm and 5mm of n1](n2){$a=a^2+2$};
\node[PD, below=8mm of n1](pd){$a<10$?};
\node[IO, below=of pd](out){输出$a$};
\node[SS, below=of out](stop){结束};
\path (start) edge (n1)
(n1) edge (pd)
(pd) edge node[right]{否}(out)
(out) edge (stop);
\draw (pd.east)node[below]{是} -| (n2);
\draw (n2) -- (n2-|n1);
\end{tikzpicture}



\begin{tikzpicture}[->]
\node[SS](start){开始};
\node[IO, below=of start](in){输入$x$, $t$};
\node[NR, below=of in](n1){$M=1$, $S=3$, $k=1$};
\node[PD, below=of n1](pd){$k\le t$};
\node[NR, on grid, below left=1cm and 2cm of pd](n3){$M=\dfrac Mkx$};
\node[IO, on grid, below right=1cm and 2cm of pd](out){输出$S$};
\node[NR, below=of n3](n4){$S=M+S$};
\node[NR, below=of n4](n5){$k=k+1$};
\node[SS, below=of out](stop){结束};
\path (start) edge (in)
(in) edge (n1)
(n1) edge (pd)
(n3) edge (n4)
(n4) edge (n5)
(out) edge (stop);
\draw (pd) -| node[left]{是} (n3);
\draw (pd) -| node[right]{否} (out);
\draw (n5.west)--++(-0.5,0) |- ($(n1.south)!0.5!(pd.north)$);
\end{tikzpicture}
%
%
\begin{tikzpicture}[->]
\node[SS](start){开始};
\node[NR, below=of start](n1){$S=0$, $T=0$, $n=0$};
\node[PD, below=of n1](pd){$T>S$};
\node[NR, below=of pd](n2){$S=S+5$};
\node[NR, below=of n2](n3){$n=n+2$};
\node[NR, below=of n3](n4){$T=T+n$};
\node[IO, right=of n2](out){输出$T$};
\node[SS, below=of out](stop){结束};
\path (start) edge (n1)
(n1) edge (pd)
(pd) edge node[right]{否} (n2)
(n2) edge (n3)
(n3) edge (n4)
(out) edge (stop);
\draw (n4.south) --++(0,-0.2) -| ($(pd.west)+(-0.5,0)$)--(pd);
\draw (pd.east)node[above]{是} -| (out);
\end{tikzpicture}



\begin{tikzpicture}[node distance=3mm,->]
\node[SS](start){开始};
\node[IO, right=of start](in){输入$a$, $b$, $k$};
\node[NR, right=of in](n1){$n=1$};
\node[NR, below right=8mm and -5mm of n1](n2){$n=n+1$};
\node[NR, right=of n2](n3){$b=M$};
\node[NR, right=of n3](n4){$a=b$};
\node[NR, right=of n4](n5){$M=a+\dfrac1b$};
\node[PD] at (n1-|n5) (pd){$n\le k$?};
\node[IO, right=of pd](out){输出$M$};
\node[SS, right=of out](stop){结束};
\path (start) edge (in)
(in) edge (n1)
(n1) edge (pd)
(pd) edge node [right] {是}(n5)
(n5) edge (n4)
(n4) edge (n3)
(n3) edge (n2)
(n2) edge (n2|-n1)
(pd) edge node [above] {否} (out)
(out) edge (stop);
\end{tikzpicture}


\begin{tikzpicture}[->]
\node[SS](start){开始};
\node[IO, below=of start](in){输入$x_1$, $x_2$};
\node[PD, below=of in](pd){$|x_1-x_2|\le2$};
\node[IO, below=of pd](in2){输入$x_3$};
\node[PD, below=of in2](pd2){$|x_3-x_1|<|x_3-x_2|$};
\node[NR, below=of pd2](n1){$x_1=x_3$};
\node[NR, left=15mm of n1](n2){$x_2=x_3$};
\node[NR, below=of n1](n3){$p=\dfrac{x_1+x_2}2$};
\node[IO, below=of n3](out){输出$p$};
\node[SS, below=of out](stop){结束};
\path (start) edge (in)
(in) edge (pd)
(pd) edge node[right]{否} (in2)
(in2) edge (pd2)
(pd2) edge node[right]{否} (n1)
(n1) edge (n3)
(n3) edge (out)
(out) edge (stop);
\draw (pd.east)node[above]{是} -- ++(1,0) |- ($(n1.south)!0.5!(n3.north)$);
\draw (pd2.west)node[above]{是} -| (n2);
\draw (n2) |- ($(n1.south)!0.5!(n3.north)$);
\end{tikzpicture}
%
%
\newcommand\tabincell[2][c]{%
\begin{tabular}{@{}#1@{}}#2\end{tabular}}
%
\begin{tikzpicture}[->]
\node[SS](start){开始};
\node[IO, below=of start](in){输入$x$, $y$};
\node[PD, aspect = 3, inner sep=0pt,
below=of in](pd){%
\linespread{0.8}\selectfont
\tabincell{$x\ge0$, $y\ge0$,\\$x+y\le1$?}
};
\node[NR, on grid, below left=1cm and 2.5cm of pd](n1){$S=2x+y$};
\node[NR, on grid, below right=1cm and 2.5cm of pd](n2){$S=1$};
\node[IO, below=12mm of pd](out){输出$S$};
\node[SS, below=of out](stop){结束};
\path (start) edge (in)
(in) edge (pd)
(out) edge (stop);
\draw (pd.west)node[above]{是} -| (n1);
\draw (pd.east)node[above]{否} -| (n2);
\draw (n1)|-($(out.north)+(0,0.3)$)--(out);
\draw (n2)|-($(out.north)+(0,0.3)$)--(out);
\end{tikzpicture}


\end{document}
