\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}

\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,chains}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{matrix}
\title{Fundamentals of Computing: Lecture 3}
\usepackage{pgfkeys}
\pgfkeys %
    {%
       /tikz/noise/.style={
        starburst,
        draw=red
      },
      /tikz/qnoise/.style={
        starburst,
        fill=yellow,
        draw=red
      },
      /tikz/boxcolor/.style={
	draw=black
	top color=white,
	bottom color=red!50!black!50
      },
      /tikz/box/.style={
	rectangle,
	minimum size=1cm,
	/tikz/boxcolor
      },
      /tikz/unbox/.style={
	rectangle,
	minimum size=1cm
      },
      /tikz/point/.style={rectangle,minimum size=1cm}
    }

\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}
\usepackage{multicol}
\date{July 31, 2009}
\begin{document}
\begin{frame}
\maketitle
\end{frame}
\begin{frame}
  \frametitle{Getting started}

  
  You need to first creat a file using the editor.
  Use one of vi/emacs.

  The Lab TA will tell you how to use the editor.

  \begin{block}{Algorithm to creating a file and execute}
 
    \begin{enumerate}
    \item Open the file with the editor
      \begin{tabbing}\tt
~~~~~~~~~\char36{}~emacs~foo\char46{}c
\end{tabbing}
    \item Edit the program save and exit. \label{step-edit}
    \item Compile the program\begin{tabbing}\tt
~~~~~~~~~\char36{}~gcc~foo\char46{}c
\end{tabbing}
    \item If there are errors go to step~\ref{step-edit}
    \item Run the program\begin{tabbing}\tt
~~~~~~~~~~\char36{}~\char46{}\char47{}a\char46{}out
\end{tabbing}
    \end{enumerate}
    \end{block} 
\end{frame}

\begin{frame}
  \frametitle{The first C program}
  
  \begin{tabbing}\tt
~~~~~\char35{}include\char60{}stdio\char46{}h\char62{}\\
\tt ~~~~~\\
\tt ~~~~~int~main\char40{}\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~printf\char40{}\char34{}The~answer~is~42\char34{}\char41{}\\
\tt ~~~~~\char125{}
\end{tabbing}
\end{frame}


\begin{frame}
  \frametitle{Variables}
  \begin{tabbing}\tt
~~~~~\char35{}include~\char60{}stdio\char46{}h\char62{}\\
\tt ~~~~~\\
\tt ~~~~~int~main\char40{}\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~int~answer~\char61{}~41\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}The~answer~is~\char37{}d\char34{}\char44{}answer\char41{}\char59{}\\
\tt ~~~~~~~answer~\char61{}~answer~~\char43{}~1\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}The~answer~is~\char37{}d\char34{}\char44{}answer\char41{}\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}

  \begin{block}{Rule for variable names}
  A variable name can start with any letter and contain
  any letter digit. The symbol \text{\tt \char39{}\char95{}\char39{}} is treated as a letter.

  eg \text{\tt x123}, \text{\tt \char95{}x123}

  non examples \text{\tt 23x}
  \end{block}

\end{frame}

\begin{frame}
 \frametitle{Basic types}
  \begin{enumerate}
  \item Integers\begin{tabbing}\tt
~~~~~~int~~i~\char61{}~100\char59{}
\end{tabbing}
   \item Character\begin{tabbing}\tt
~~~~~~char~~c~\char61{}~\char39{}a\char39{}\char59{}
\end{tabbing}
   \item Floting point numbers\begin{tabbing}\tt
~~~~~~float~f~\char61{}~1\char46{}234\char59{}
\end{tabbing}
  \end{enumerate}     
\end{frame}

\begin{frame}
\frametitle{Expression}

\begin{itemize}
\item Usual aritmetic expressions.
 
 eg \text{\tt x~\char43{}~y~\char42{}~3}

\item Relational expressions 
 \begin{tabbing}\tt
~~~~~~~~~~x~\char60{}\char61{}~15
\end{tabbing}
\item Boolean (truth) expressions\begin{tabbing}\tt
~~~\char40{}x~\char60{}\char61{}~10\char41{}~\char124{}\char124{}~\char40{}y~\char60{}~100\char41{}~\char38{}\char38{}~\char40{}10~\char62{}~100\char41{}
\end{tabbing}
Here the operator \text{\tt \char124{}\char124{}} denotes a logical OR function and \text{\tt \char38{}\char38{}} denote
logical AND function.

\end{itemize}

\begin{block}{Important point}

C does not have Boolean (or truth) type.  Integers, characters, etc
are treated like boolean. Zero is treated as False and non-zero as
True.

\end{block}
\end{frame}

\begin{frame}
\frametitle{Operator Precedence}
 What does  \text{\tt 2~\char43{}~3\char42{}6~\char62{}~5~\char38{}\char38{}~5~\char60{}~2} mean ?
 \pause
 \begin{block}{Precedence rules among different kinds of operators}
   \begin{itemize}
   \item Arithmetic has highest
   \item then comes relational.
   \item then comes boolean.
   \end{itemize}
 \end{block}
 \begin{block}{Among arithmetic operators}
   \begin{itemize}
   \item \text{\tt \char42{}} and \text{\tt \char47{}} have more precedence than \text{\tt \char43{}} and \text{\tt \char45{}}.
   \item Unary operator has more precedence than binary.
   \end{itemize}
 \end{block}
\end{frame}

\begin{frame}
\frametitle{Factorial program}

\begin{tabbing}\tt
~\char35{}~include\char60{}stdio\char46{}h\char62{}\\
\tt ~\\
\tt ~int~main\char40{}\char41{}\char123{}\\
\tt ~~~~int~n~\char61{}~100\char59{}\\
\tt ~~~~int~i~\char61{}~1\char59{}\\
\tt ~~~~int~fact~\char61{}~1\char59{}\\
\tt ~~~~while\char40{}i~\char60{}\char61{}~n\char41{}\\
\tt ~~~~\char123{}\\
\tt ~~~~~~~fact~\char61{}~fact~\char42{}~i\char59{}\\
\tt ~~~~~~~i~\char61{}~i~\char43{}~1\char59{}\\
\tt ~~~~\char125{}\\
\tt ~~~~printf\char40{}\char34{}The~factorial~of~\char37{}d~is~\char37{}d\char34{}\char44{}~n~\char44{}~fact\char41{}\char59{}\\
\tt ~\char125{}
\end{tabbing}
    

\end{frame}
\end{document}
