\documentclass{beamer}
%
%
\makeatletter
\@ifundefined{lhs2tex.lhs2tex.sty.read}%
  {\@namedef{lhs2tex.lhs2tex.sty.read}{}%
   \newcommand\SkipToFmtEnd{}%
   \newcommand\EndFmtInput{}%
   \long\def\SkipToFmtEnd#1\EndFmtInput{}%
  }\SkipToFmtEnd

\newcommand\ReadOnlyOnce[1]{\@ifundefined{#1}{\@namedef{#1}{}}\SkipToFmtEnd}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{stmaryrd}
\DeclareFontFamily{OT1}{cmtex}{}
\DeclareFontShape{OT1}{cmtex}{m}{n}
  {<5><6><7><8>cmtex8
   <9>cmtex9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmtex10}{}
\DeclareFontShape{OT1}{cmtex}{m}{it}
  {<-> ssub * cmtt/m/it}{}
\newcommand{\texfamily}{\fontfamily{cmtex}\selectfont}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
  {<5><6><7><8>cmtt8
   <9>cmbtt9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmbtt10}{}
\DeclareFontShape{OT1}{cmtex}{bx}{n}
  {<-> ssub * cmtt/bx/n}{}
\newcommand{\tex}[1]{\text{\texfamily#1}}	% NEU

\newcommand{\Sp}{\hskip.33334em\relax}
\newcommand{\NB}{\textbf{NB}}
\newcommand{\Todo}[1]{$\langle$\textbf{To do:}~#1$\rangle$}

\EndFmtInput
\makeatother
%
\author{Piyush P Kurur\\
  Office no: 224\\
  Dept. of Comp. Sci. and Engg.\\
  IIT Kanpur}


\newcommand{\Token}[2][]{\node(#2#1)[token]{#2};}
\newcommand{\Symbol}[2][]{\node(#2#1)[symbol]{#2};}
\newcommand{\Point}[1]{\node(#1)[point]{#1};}


\title{Fundamentals of Computing: Lecture 6}
\date{August 7, 2009}
\begin{document}

\begin{frame}
\maketitle
\end{frame}

\begin{frame}
  \frametitle{Summary of previous lecture: Statement}
  \begin{itemize}
  \item Simple statemets are expressions followed by \text{\tt \char59{}}
  \item Compound statements are a sequence of statements enclosed in a pair of braces.
  \item Conditionals; \text{\tt if} and \text{\tt if~else} statements.
  \item Loops; while loop and for loop.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Arrays}
  \begin{block}{Declaration}
  type variable[integer];
  type variable[]={values};
  \end{block}
  Eg,
  \begin{tabbing}\tt
~~~~~int~x\char91{}100\char93{}\char59{}\\
\tt ~~~~~double~mass\char91{}100\char93{}\char59{}\\
\tt ~~~~~int~u\char91{}\char93{}~\char61{}~\char123{}10\char44{}11\char44{}12\char44{}13\char44{}14\char125{}
\end{tabbing}

\end{frame}

\begin{frame}
  \frametitle{Character type}
  \begin{tabbing}\tt
~~~~~char~foo~\char61{}~\char39{}A\char39{}\char59{}\\
\tt ~~~~~char~foo~\char61{}~\char39{}\char92{}65\char39{}\char59{}\\
\tt ~~~~~char~foo~\char61{}~65\char59{}
\end{tabbing}
  
  \pause
  \begin{block}{Character escapes}
    \begin{itemize}
    \item \text{\tt \char39{}\char92{}n\char39{}} is new line,
      \pause
    \item \text{\tt \char39{}\char92{}t\char39{}} is tab,
      \pause
    \item \text{\tt \char39{}\char92{}65\char39{}} is the character with ascii value 65,
      \pause
    \item \text{\tt \char39{}\char92{}\char92{}\char39{}} is a back slash character.
    \end{itemize}
  \end{block}
  
\end{frame}
  
\begin{frame}
  \frametitle{Strings}
  \begin{itemize}
  \item Strings are character array.
  \item Strings are terminated with a null character \text{\tt \char39{}\char92{}0\char39{}}.
  \end{itemize}
  \begin{tabbing}\tt
~~~~~char~mesg\char91{}\char93{}~\char61{}~\char123{}~\char39{}h\char39{}\char44{}\char39{}e\char39{}\char44{}\char39{}l\char39{}\char44{}\char39{}l\char39{}\char44{}\char39{}o\char39{}\char44{}\char39{}\char92{}0\char39{}\char125{}\\
\tt ~~~~~char~mesg\char91{}\char93{}~\char61{}~\char34{}hello\char34{}\char59{}
\end{tabbing}
  
\end{frame}

\begin{frame}

  \frametitle{The \text{\tt printf} and \text{\tt scanf} function}

  \begin{tabbing}\tt
~~~~~printf\char40{}fmtstring\char44{}e\char95{}1\char44{}e\char95{}2\char46{}\char46{}\char46{}e\char95{}n\char41{}\char59{}\\
\tt ~~~~~scanf\char40{}fmtstring\char44{}\char38{}v1\char44{}\char38{}v2\char44{}\char46{}\char46{}\char46{}\char44{}\char38{}v\char95{}n\char41{}\char59{}
\end{tabbing}
  
  Eg.
  \begin{tabbing}\tt
~~~~~\char35{}include~\char60{}stdio\char46{}h\char62{}\\
\tt ~~~~~int~main\char40{}\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~double~h\char44{}w\char59{}\\
\tt ~~~~~~~double~area\char44{}per\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}Enter~the~height~and~width\char58{}~\char34{}\char41{}\char59{}\\
\tt ~~~~~~~scanf\char40{}\char34{}\char37{}g~\char37{}g\char34{}\char44{}h\char44{}w\char41{}\char59{}\\
\tt ~~~~~~~area~\char61{}~h~\char42{}~w\char59{}\\
\tt ~~~~~~~per~~\char61{}~2~\char42{}~\char40{}h~\char43{}~w\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}For~a~\char37{}g~x~\char37{}g~rectangle\char92{}n\char92{}t\char34{}\char44{}h\char44{}w\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}Area~\char61{}~\char37{}g\char92{}n\char92{}tPerimeter~\char61{}~\char37{}g\char92{}n\char34{}\char44{}~area\char44{}~per\char41{}\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}
\end{frame}
\begin{frame}
  \frametitle{Format specifier for \text{\tt printf} and \text{\tt scanf}}

  \begin{itemize}
  \item All formating specifier is a \text{\tt \char37{}} followed by a character,
  \item To print a literal \text{\tt \char37{}} use \text{\tt \char37{}\char37{}},
  \item Depending on what follows \text{\tt \char37{}} we have the following meanings
    \begin{tabular}{ll}
      \text{\tt d}, \text{\tt x}, \text{\tt o} &  integer in decimal, hex or octal\\
      \text{\tt f}           & float\\
      \text{\tt g}           & generic floating point, i.e. float or double.\\
      \text{\tt c}           & character
    \end{tabular}
  \end{itemize}
  For more formating characters check out manpage of scanf.
\end{frame}
\end{document}





\begin{frame}
  \frametitle{How to design loops?}
  
  \begin{definition}
    An invarient of a loop is a condition that is
    true always during the execution of the loop.
  \end{definition}
  
  Eg.
  
  \begin{tabbing}\tt
~~~~~int~sum~\char61{}~0\char59{}\\
\tt ~~~~~int~i~~~\char61{}~0\char59{}\\
\tt ~~~~~while\char40{}~i~\char60{}~n\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~i\char43{}\char43{}\char59{}\\
\tt ~~~~~~~sum~\char43{}\char61{}~i\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}

  A nice invarient is $sum = \sum_{j=0}^i i$.
  
\end{frame}



