%------------------------------------------------------- % exercise3.tex % Exercise 3. % % Irit Dinur %-------------------------------------------------------- \documentclass[12pt]{article} %\documentclass[twocolumn]{article} \usepackage{alltt,url,amstext,amsmath,amssymb} \setlength{\evensidemargin}{.0in} \setlength{\oddsidemargin}{-0.3in} \setlength{\textwidth}{6.8in} \setlength{\textheight}{8.7in} \newcommand{\sep}[1]{\,\left|\, {#1} \MakeBig\right.} \newcommand{\brc}[1]{\left\{ {#1} \right\}} \newcommand{\pth}[1]{\left( {#1} \right)} \newcommand{\ceil}[1]{\left\lceil {#1} \right\rceil} \newcommand{\floor}[1]{\left\lfloor {#1} \right\rfloor} \newcommand{\remove}[1]{} \newtheorem{theorem}{Theorem}[section] % section \newtheorem{lemma}[theorem]{Lemma} \newtheorem{example}[theorem]{Example} \newtheorem{defn}[theorem]{Definition} \newcommand{\ctrl}{{\symbol{'136}}} \newcommand{\examplex}[3]{ \vspace{0.2cm} \noindent{\tt #1} \noindent{\bf \large Input:} {\tt #2} \noindent{\bf \large Output:}{\tt #3} \vspace{0.2cm} } \newcommand{\exmpinp}{\noindent{\bf \large Input:}\vspace{-0.3cm}} \newcommand{\exmpout}{\noindent{\bf \large Output:}\vspace{-0.3cm}} \newcommand{\MakeBig}{\rule[-.2cm]{0cm}{0.6cm}} \newcommand{\unix}{{\tt UNIX}} \newcommand{\dos}{{\tt DOS}} \newcommand{\exercise}[2]{\section*{Ex {#1} ~ {#2}}} \newcommand{\tildegen}{\protect\raisebox{-0.12cm}{\symbol{'176}}} \newcommand{\atgen}{\symbol{'100}} \newcommand{\email}{{\tt sariel\atgen{}math.tau.ac.il}} \newcommand{\homepage}{{\tt http://www.math.tau.ac.il/\tildegen{}sariel/}} % Title \title{Introduction to Computer Science - Fall Semester 1998/9\\ { {{Exercise}} 3}} \author{{\bf Due:} 7/1/1999} \date{} \begin{document} \maketitle \section*{Some Matrices} Write a program that asks the user for a positive integer $n$, and prints the following $n\times n$ matrices on the screen: \begin{enumerate} \item The zero matrix. \item The unit matrix. \item The matrix with ones on both diagonals and zeros everywhere else. \end{enumerate} For example: \begin{verbatim} Please enter the dimension of the matrices: 5 The 5x5 matrices are: The zero matrix = 00000 00000 00000 00000 00000 The unit matrix = 10000 01000 00100 00010 00001 The X matrix = 10001 01010 00100 01010 10001 \end{verbatim} The program should check if the user entered a negative (or zero) number and output an error message. \end{document}