Exercises for Computer Science
Autor
abfatih
Letzte Aktualisierung
vor 9 Jahren
Lizenz
Other (as stated in the work)
Abstrakt
Exercises sheet for high school students in Skoura-Boulmane , Morocco
Exercises sheet for high school students in Skoura-Boulmane , Morocco
\documentclass[10pt,a4paper,notitlepage]{article}
%Mise en page
\usepackage[left=2cm, right=2cm, lines=45, top=0.8in, bottom=0.7in]{geometry}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{pdfpages}
\renewcommand{\headrulewidth}{1.5pt}
\renewcommand{\footrulewidth}{1.5pt}
\pagestyle{fancy}
\newcommand\Loadedframemethod{TikZ}
\usepackage[framemethod=\Loadedframemethod]{mdframed}
\usepackage{tikz}
\usetikzlibrary{calc,through,backgrounds}
\usetikzlibrary{matrix,positioning}
%Desssins geometriques
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{datavisualization}
\usetikzlibrary{automata} % LATEX and plain TEX
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{pgfplots}
\usepackage{physics}
\usepackage{titletoc}
\usepackage{mathpazo}
\usepackage{algpseudocode}
\usepackage{algorithmicx}
\usepackage{bohr}
\usepackage{xlop}
\usepackage{bbding}
%\usepackage{minibox}
%Ecriture arabe
\usepackage{mathdesign}
\usepackage{bbding}
\usepackage{romande}
\lhead{
\textbf{LYCEE COLLEGIAL CHARIF IDRISSI}
}
\rhead{\textbf{INFORMATIQUE}
}
\chead{\textbf{
TCS
}}
\lfoot{}
\cfoot{\textbf{$\mathsf{2015-2016}$}}
%\rfoot{\textit{Pr. $\mathcal{A}$.Kaal}}
%=====================Algo setup
\algblock{If}{EndIf}
\algcblock[If]{If}{ElsIf}{EndIf}
\algcblock{If}{Else}{EndIf}
\algrenewtext{If}{\textbf{si}}
\algrenewtext{Else}{\textbf{sinon}}
\algrenewtext{EndIf}{\textbf{finsi}}
\algrenewtext{Then}{\textbf{alors}}
\algrenewtext{While}{\textbf{tant que}}
\algrenewtext{EndWhile}{\textbf{fin tant que}}
\algrenewtext{Repeat}{\textbf{r\'ep\'eter}}
\algrenewtext{Until}{\textbf{jusqu'\`a}}
\algcblockdefx[Strange]{If}{Eeee}{Oooo}
[1]{\textbf{Eeee} "#1"}
{\textbf{Wuuuups\dots}}
\algrenewcommand\algorithmicwhile{\textbf{TantQue}}
\algrenewcommand\algorithmicdo{\textbf{Faire}}
\algrenewcommand\algorithmicend{\textbf{Fin}}
\algrenewcommand\algorithmicrequire{\textbf{Variables}}
\algrenewcommand\algorithmicensure{\textbf{Constante}}% replace ensure by constante
\algblock[block]{Begin}{End}
\newcommand\algo[1]{\textbf{algorithme} #1;}
\newcommand\vars{\textbf{variables } }
\newcommand\consts{\textbf{constantes}}
\algrenewtext{Begin}{\textbf{debut}}
\algrenewtext{End}{\textbf{fin}}
%================================
%================================
\setlength{\parskip}{1cm}
\setlength{\parindent}{1cm}
\tikzstyle{titregris} =
[draw=gray,fill=white, shading = exersicetitle, %
text=gray, rectangle, rounded corners, right,minimum height=.3cm]
\pgfdeclarehorizontalshading{exersicebackground}{100bp}
{color(0bp)=(green!40); color(100bp)=(black!5)}
\pgfdeclarehorizontalshading{exersicetitle}{100bp}
{color(0bp)=(red!40);color(100bp)=(black!5)}
\newcounter{exercise}
\renewcommand*\theexercise{exercice \textbf{Exercice}~n\arabic{exercise}}
\makeatletter
\def\mdf@@exercisepoints{}%new mdframed key:
\define@key{mdf}{exercisepoints}{%
\def\mdf@@exercisepoints{#1}
}
\mdfdefinestyle{exercisestyle}{%
outerlinewidth=1em,outerlinecolor=white,%
leftmargin=-1em,rightmargin=-1em,%
middlelinewidth=0.5pt,roundcorner=3pt,linecolor=black,
apptotikzsetting={\tikzset{mdfbackground/.append style ={%
shading = exersicebackground}}},
innertopmargin=0.1\baselineskip,
skipabove={\dimexpr0.1\baselineskip+0\topskip\relax},
skipbelow={-0.1em},
needspace=0.5\baselineskip,
frametitlefont=\sffamily\bfseries,
settings={\global\stepcounter{exercise}},
singleextra={%
\node[titregris,xshift=0.5cm] at (P-|O) %
{~\mdf@frametitlefont{\theexercise}~};
\ifdefempty{\mdf@@exercisepoints}%
{}%
{\node[titregris,left,xshift=-1cm] at (P)%
{~\mdf@frametitlefont{\mdf@@exercisepoints points}~};}%
},
firstextra={%
\node[titregris,xshift=1cm] at (P-|O) %
{~\mdf@frametitlefont{\theexercise}~};
\ifdefempty{\mdf@@exercisepoints}%
{}%
{\node[titregris,left,xshift=-1cm] at (P)%
{~\mdf@frametitlefont{\mdf@@exercisepoints points}~};}%
},
}
\makeatother
%%%%%%%%%
%%%%%%%%%%%%%%%
\mdfdefinestyle{theoremstyle}{%
outerlinewidth=0.01em,linecolor=black,middlelinewidth=0.5pt,%
frametitlerule=true,roundcorner=2pt,%
apptotikzsetting={\tikzset{mfframetitlebackground/.append style={%
shade,left color=white, right color=blue!20}}},
frametitlerulecolor=black,innertopmargin=1\baselineskip,%green!60,
innerbottommargin=0.5\baselineskip,
frametitlerulewidth=0.1pt,
innertopmargin=0.7\topskip,skipabove={\dimexpr0.2\baselineskip+0.1\topskip\relax},
frametitleaboveskip=1pt,
frametitlebelowskip=1pt
}
\setlength{\parskip}{0mm}
\setlength{\parindent}{10mm}
\mdtheorem[style=theoremstyle]{definition}{\textbf{Exercice}}
%================Liste definition--numList-and alphList=============
\newcounter{alphListCounter}
\newenvironment
{alphList}
{\begin{list}
{\alph{alphListCounter})}
{\usecounter{alphListCounter}
\setlength{\rightmargin}{0cm}
\setlength{\leftmargin}{0.5cm}
\setlength{\itemsep}{0.2cm}
\setlength{\partopsep}{0cm}
\setlength{\parsep}{0cm}}
}
{\end{list}}
\newcounter{numListCounter}
\newenvironment
{numList}
{\begin{list}
{\arabic{numListCounter})}
{\usecounter{numListCounter}
\setlength{\rightmargin}{0cm}
\setlength{\leftmargin}{0.5cm}
\setlength{\itemsep}{0cm}
\setlength{\partopsep}{0cm}
\setlength{\parsep}{0cm}}
}
{\end{list}}
%===========================================================
\begin{document}
\begin{center}
\large{\textbf{Serie N\textdegree 6: \textsc{Structures it\'eratives}}}
\end{center}
\begin{definition}[]
\hspace{2ex}Ecrire, en utilisant la boucle \textbf{Pour}, les algorithmes qui effecturent les calculs suivants
\begin{enumerate}
\item
\begin{tabular}{p{3cm}p{3cm}p{3cm}}
a) S = $\sum_{i=1}^{20} i$ & b) S = $\sum_{i=1}^{20} i^2$ & c) S = $ \sum_{i=1}^{20} i^i$
\end{tabular}
\item
\begin{tabular}{p{3cm}p{3cm}p{3cm}}
a) P = $\prod_{k=1}^{20} k$ & b) P = $ \prod_{k=1}^{20} k^2$ &c) P = $ \prod_{k=1}^{20} k^k $\\
\end{tabular}
\end{enumerate}
\end{definition}
\begin{definition}
\hspace{2ex} Ecrire les boucles appropri\'es pour cacluler chacune des expressions ci-desosus\\
\begin{enumerate}
\item
\begin{tabular}{p{7cm}p{7cm}}
a) $s= 1^2-2^2+\dots +19^2-20^2$ & b)$ s = 1^1 - 2^2 + \dots +19^{19} -20^{20}$ \\
\end{tabular}
\item
\begin{tabular}{p{7cm}p{7cm}}
a) $s= 1^2\times (-2)^2 \times \dots \times 19^2 \times (-20)^{2}$&b)$ p = 1^1 \times 2^2 + \dots +19^{19} \times 20^{20}$ \\
\end{tabular}
\item
\begin{tabular}{p{7cm}p{7cm}}
a) $s= \sqrt{1}+\sqrt{2}+\dots +\sqrt{19}+\sqrt{20}$ &b)$ s = \dfrac{1^1}{\sqrt{2}} + \dfrac{2^2}{\sqrt{3}} + \dots +\dfrac{19^{19}}{\sqrt{20}}$ \\
\end{tabular}
\end{enumerate}
\end{definition}
\begin{definition}[]
\begin{minipage}{0.7\textwidth}
\hspace{2ex}Ex\'ecuter l'algorithme ci-contre avec les entr\'ee de la ligne 1 du tableau ci-dessous et compl\'eter la ligne 2.\\[2ex]
\begin{tabular}{c|c|c|c|c|c|c}
Ex\'ecution \HandRight & 1 & 2 & 3 & 4 & 5 & 6 \\
\hline
$N$ & 7 & 11 & 13 & 25 & 37 & 38 \\
\hline
$p$ & ... & ... & ... & ... & ... & ... \\
\hline
\end{tabular}
\vspace{3mm}\\
D'apr\`es les valeurs de $N$ et de $p$, que repr\'esente la valeur de $p$.
\end{minipage}
\begin{minipage}{0.3\textwidth}
\begin{scriptsize}
\begin{algorithmic}[1]
\State $p \leftarrow vrai$;
\State $i \leftarrow 2$;
\State Lire (N)
\Repeat
\State $r \leftarrow Reste(N, i)$;
\If{(r==0)} \textbf{alors}
\State $p \leftarrow faux$
\EndIf
\State $i\leftarrow i+1$
\Until{(($i>=N-1$) OU ($p==faux$))}
\end{algorithmic}
\end{scriptsize}
\end{minipage}
\end{definition}
\begin{definition}[]
\begin{minipage}{0.7\textwidth}
Ex\'ecuter l'algorithme ci-contre avec les entr\'ees $a$ et $b$ des lignes 1 et 2 du tableau ci-dessous et compl\'ter la ligne 3.\\[3ex]
\begin{tabular}{c|c|c|c|c|c|c}
Ex\'ecution \HandRight & 1 & 2 & 3 & 4 & 5 & 6 \\
\hline
$a$ & 2 & 3 & 13 & 25 & 37 & 16 \\
\hline
$b$ & 4 & 5 & 6 & 12 & 12 & 38 \\
\hline
$q$ & ... & ... & ... & ... & ... & ... \\
\hline
\end{tabular}
\vspace{3mm}
D'apr\`es les valeurs de $a$, $b$ et de $q$, qu'indique de la valeur de $q$ ?
\begin{alphList}
\item le maximum de $a$ et $b$,
\item le PGCD de $a$ et $b$,
\item le PPCM de $a$ et $b$.
\end{alphList}
\end{minipage}
\begin{minipage}{0.3\textwidth}
\begin{scriptsize}
\begin{algorithmic}[1]
\State Lire(a,b);
\State $i \leftarrow 2$;
\If{(a<b)}\textbf{}alors
\State $temp\leftarrow a$;
\State $a\leftarrow b$;
\State $b\leftarrow temp$;
\EndIf
\State $r \leftarrow Reste(a,b)$;
\While{($r<>0$)} \textbf{faire}
\State $a \leftarrow b$;
\State $b \leftarrow r$;
\State $r \leftarrow Reste(a,b)$;
\EndWhile
\State $q \leftarrow b$;
\end{algorithmic}
\end{scriptsize}
\end{minipage}
\end{definition}
\begin{definition}[]
\begin{numList}
\item Ecrire, en utilisant une structure de contr\^ole de votre choix, un algorithme qui calcule le produit suivant
$$f = \prod_{k=1}^{k=n}k = k!= 1 \times 2 \times \dots \times (n-1) \times n $$
\item Ecrire, en utilisant une structure de contr\^ole de votre choix, un algorithme qui calcule la somme
$$s = \sum_{q=1}^{q=M}q! = 1! + 2! + \dots + M!$$
\end{numList}
\end{definition}
%% Macros for ``successive divisions''
%%
%\def\Division#1#2#3{ % Dividend, divisor, remainder
% \matrix (D) [matrix of nodes,
% below=0pt of D-1-2.south east,
% row sep=1pt, column sep=1pt,
% every node/.append style={minimum width=12mm}] {
% #1 \pgfmatrixnextcell #2 \\
% |[marcar] (R#1)| #3 \\
% };
% \draw[shorten >=2pt, shorten <=2pt]
% (D-1-2.north west) |- (D-1-2.south east);
%}
%\def\FinDivision#1{
%\node[marcar, below=2pt of D-1-2.south] (C)(C) {#1};
%}
%\tikzset{marcar/.style={circle,draw,inner sep=2pt,minimum width=0pt,
%fill=yellow!10}}
%
%
%\begin{tikzpicture}
% \coordinate (D-1-2) at (0,0) {}; % We must start with this command.
% \Division{25}{2}{1} % First dividend, divisor, remainder
% \Division{12}{2}{0} % Dividend (previous quotient), divisor, remainder
% \Division{6}{2}{0}
% \Division{3}{2}{1}
% \FinDivision{1} % Last remainder.
%
%% We can draw an arrow jumping from one remainder
%% to the next one. Every reminder is a node called
%% Rdividend. Last remainder is node C.
% \draw[shorten <=1mm, ->, dashed] (C) to[out=-150,in=-65] (R3);
% \draw[shorten <=1mm, ->, dashed] (R3) to[out=-150,in=-65] (R6);
% \draw[shorten <=1mm, ->, dashed] (R6) to[out=-150,in=-65] (R12);
% \draw[shorten <=1mm, ->, dashed] (R12) to[out=-150,in=-65] (R25);
%
%% Some more information:
% \node (MSB) at ([yshift=-1.3cm]R6.south) {Most significant bit (MSB)};
% \node (LSB) at ([yshift=-2mm]MSB.south) {Less significant bit (LSB)};
%\draw[ ->] (MSB.east) to[out=30,in=-55] (C);
%\draw[ ->] (LSB.west) to[out=150,in=-95] (R25);
%\end{tikzpicture}
%\begin{center}\SnowflakeChevronBold \SnowflakeChevronBold \SnowflakeChevronBold \end{center}
%%----------------------------------------------------------------------------------------------------------------------------------------
%
%%\includepdf[doublepages=true]{serie55}
\end{document}