\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{phon} \pdfinfo{ /Title (hallo.pdf) /Creator (Cheatography) /Author (phon) /Subject (Hallo? Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Hallo? Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{phon} via \textcolor{DarkBackground}{\uline{cheatography.com/25871/cs/18251/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}phon \\ \uline{cheatography.com/phon} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 12th December, 2018.\\ Updated 12th December, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{2D array with random}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}stdlib.h\textgreater{} \newline \#include \textless{}time.h\textgreater{} \newline \newline int main()\{ \newline int a{[}3{]}{[}4{]}; \newline int sum1{[}3{]} = \{0,0,0\}; \newline int sum2{[}4{]} = \{0,0,0,0\}; \newline srand(time(NULL)); \newline for(int x = 0; x \textless{} 3;x++)\{ \newline for (int y = 0; y \textless{} 4;y++)\{ \newline a{[}x{]}{[}y{]} = rand() \% 10; \newline printf("\%d ",a{[}x{]}{[}y{]}); \newline \} \newline printf("\textbackslash{}n"); \newline \} \newline int count1 = 0; \newline for(int ax = 0; ax \textless{} 3;ax++)\{ \newline for (int ay = 0; ay \textless{} 4;ay++)\{ \newline sum1{[}count1{]} += a{[}ax{]}{[}ay{]}; \newline \} \newline count1++; \newline \} \newline int count2 = 0; \newline for(int bx = 0;bx \textless{} 4;bx++)\{ \newline for (int by = 0;by \textless{}3;by++)\{ \newline sum2{[}count2{]} += a{[}by{]}{[}bx{]}; \newline \} \newline count2++; \newline \} \newline printf("Sum of rows:"); \newline for (int c = 0;c \textless{} 3;c++)\{ \newline printf(" \%d",sum1{[}c{]}); \newline \} \newline printf("\textbackslash{}nSum of columns:"); \newline for (int d = 0;d \textless{} 4;d++)\{ \newline printf(" \%d",sum2{[}d{]}); \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Lab1 wk10}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline void check(int a,float b, double c)\{ \newline printf("The integer is \%d",a); \newline printf("\textbackslash{}nThe floating point number is \%f",b); \newline printf("\textbackslash{}nThe double precision number is \%lf",c); \newline \} \newline \newline int main()\{ \newline int a; \newline float b; \newline double c; \newline printf("Enter an integer: "); \newline scanf("\%d",\&a); \newline printf("Enter a floating point number: "); \newline scanf("\%f",\&b); \newline printf("Enter a double precision number "); \newline scanf("\%lf",\&c); \newline check(a,b,c); \newline \} \newline \newline Enter an integer: 3 \newline Enter a floating point number: 4.5 \newline Enter a double precision number 5.3456 \newline The integer is 3 \newline The floating point number is 4.500000 \newline The double precision number is 5.345600} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{bonuslab wk10(find distance)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}math.h\textgreater{} \newline double euc\_dist(double a,double b,double c,double d)\{ \newline double x = sqrt(pow(c-a,2)+pow(d-b,2)); \newline return x; \newline \} \newline int main()\{ \newline double a,b,c,d,z; \newline printf("Please enter a value for x1: "); \newline scanf("\%lf",\&a); \newline printf("Please enter a value for y1: "); \newline scanf("\%lf",\&b); \newline printf("Please enter a value for x2: "); \newline scanf("\%lf",\&c); \newline printf("Please enter a value for y2: "); \newline scanf("\%lf",\&d); \newline z = euc\_dist(a,b,c,d); \newline printf("The distance between the points is: \%lf",z); \newline \} \newline \newline Please enter a value for x1: 20.5 \newline Please enter a value for y1: 55 \newline Please enter a value for x2: 60 \newline Please enter a value for y2: 40.7 \newline The distance between the points is: 42.008809} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{lab1 wk11}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#define USD 32.86; \newline \#define JPY 0.29; \newline float THB2USD(float THB)\{ \newline float x = THB / USD; \newline return x; \newline \} \newline float THB2JPY(float THB)\{ \newline float y = THB / JPY; \newline return y; \newline \} \newline void main()\{ \newline float THB = 5000; \newline printf("\%.2f THB = \%.2f USD\textbackslash{}n",THB,THB2USD(THB)); \newline printf("\%.2f THB = \%.2f JPY",THB,THB2JPY(THB)); \newline \} \newline \newline 5000.00 THB = 152.16 USD \newline 5000.00 THB = 17241.38 JPY} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#6}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline void findMinMax(int array{[}{]},int nElems,int {\emph{max,int }}min); \newline int main()\{ \newline int nElems, min\_, max\_; \newline printf("input n: "); \newline scanf("\%d", \&nElems); \newline int array{[}nElems{]}; \newline printf("input array of size n: "); \newline for(int i = 0; i \textless{} nElems; i++)\{ \newline scanf("\%d",\&array{[}i{]}); \newline \} \newline findMinMax(array,nElems,\&max\_,\&min\_); \newline printf("min is \%d max is \%d", min\_, max\_); \newline return 0; \newline \} \newline void findMinMax(int array{[}{]},int nElems,int {\emph{max,int }}min)\{ \newline {\emph{min = array{[}0{]}; \newline }}max = array{[}0{]}; \newline for (int i = 1; i \textless{} nElems;i++)\{ \newline if ({\emph{min \textgreater{} array{[}i{]})\{ \newline }}min = array{[}i{]}; \newline \} \newline if ({\emph{max \textless{} array{[}i{]})\{ \newline }}max = array{[}i{]}; \newline \} \newline \} \newline \} \newline \newline input n: 6 \newline input array of size n: 1 2 3 4 5 6 \newline min is 1 max is 6} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{swap using pointer}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include\textless{}stdio.h\textgreater{} \newline void sort\_nums(int {\emph{a, int }}b, int {\emph{c); \newline void swap(int }}x, int {\emph{y); \newline int a,b,c,}}A,{\emph{B,}}C; \newline int main()\{ \newline printf("Enter 3 integers: "); \newline scanf("\%d \%d \%d",\&a,\&b,\&c); \newline A=\&a;B=\&b;C=\&c; \newline sort\_nums(A,B,C); \newline printf("Sorted integers: \%d \%d \%d",{\emph{A,}}B,{\emph{C); \newline \} \newline void sort\_nums(int }}a, int {\emph{b, int }}c)\{ \newline int loop = 1; \newline while (loop == 1)\{ \newline if ({\emph{a \textless{} }}b)\{ \newline swap(a, b); \newline \} \newline if ({\emph{b \textless{} }}c)\{ \newline swap(b, c); \newline \} \newline if ({\emph{a \textgreater{}= }}b \&\& {\emph{b \textgreater{}= }}c \&\& {\emph{a \textgreater{}= }}c)\{ \newline loop = 0; \newline \} \newline \} \newline \} \newline void swap(int {\emph{x, int }}y)\{ \newline int temp; \newline temp = {\emph{x; \newline }}x = {\emph{y; \newline }}y = temp; \newline \} \newline \newline Enter 3 integers: 2 4 5 \newline Sorted integers: 5 4 2} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{string(compare)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}string.h\textgreater{} \newline struct person\{ \newline char Name{[}2{]} {[}81{]}; \newline char Phone{[}2{]} {[}11{]}; \newline \} contact; \newline int main()\{ \newline printf("Enter Name\#1: "); \newline scanf("\%s",contact.Name{[}0{]}); \newline printf("Enter phone\#1: "); \newline scanf("\%s",contact.Phone{[}0{]}); \newline printf("Enter Name\#2: "); \newline scanf("\%s",contact.Name{[}1{]}); \newline printf("Enter phone\#2: "); \newline scanf(" \%s",contact.Phone{[}1{]}); \newline printf("Sort by: name\textbackslash{}n"); \newline if (strncmp(contact.Name{[}0{]},contact.Name{[}1{]},81) \textless{} 0)\{ // first one is less than second one \newline printf("\%s ",contact.Name{[}0{]}); \newline printf("\%s",contact.Phone{[}0{]}); \newline printf("\textbackslash{}n\%s ",contact.Name{[}1{]}); \newline printf("\%s",contact.Phone{[}1{]}); \newline \} \newline else if (strncmp(contact.Name{[}0{]},contact.Name{[}1{]},81) \textgreater{} 0)\{ // first one is greater than second one \newline printf("\%s ",contact.Name{[}1{]}); \newline printf("\%s",contact.Phone{[}1{]}); \newline printf("\textbackslash{}n\%s ",contact.Name{[}0{]}); \newline printf("\%s",contact.Phone{[}0{]}); \newline \} \newline else\{ // == 0 first one is equal to last one \newline printf("\%s ",contact.Name{[}0{]}); \newline printf("\%s",contact.Phone{[}0{]}); \newline printf("\textbackslash{}n\%s ",contact.Name{[}1{]}); \newline printf("\%s",contact.Phone{[}1{]}); \newline \} \newline printf("\textbackslash{}n"); \newline printf("Sort by: phone\textbackslash{}n"); \newline if (strncmp(contact.Phone{[}0{]},contact.Phone{[}1{]},11) \textless{} 0)\{ \newline printf("\%s ",contact.Name{[}0{]}); \newline printf("\%s",contact.Phone{[}0{]}); \newline printf("\textbackslash{}n\%s ",contact.Name{[}1{]}); \newline printf("\%s",contact.Phone{[}1{]}); \newline \} \newline else if (strncmp(contact.Phone{[}0{]},contact.Phone{[}1{]},11) \textgreater{} 0)\{ \newline printf("\%s ",contact.Name{[}1{]}); \newline printf("\%s",contact.Phone{[}1{]}); \newline printf("\textbackslash{}n\%s ",contact.Name{[}0{]}); \newline printf("\%s",contact.Phone{[}0{]}); \newline \} \newline else\{ \newline printf("\%s ",contact.Name{[}0{]}); \newline printf("\%s",contact.Phone{[}0{]}); \newline printf("\textbackslash{}n\%s ",contact.Name{[}1{]}); \newline printf("\%s",contact.Phone{[}1{]}); \newline \} \newline \} \newline \newline Enter Name\#1: Alice \newline Enter phone\#1: 0819998888 \newline Enter Name\#2: Mallory \newline Enter phone\#2: 0810001111 \newline Sort by: name \newline Alice 0819998888 \newline Mallory 0810001111 \newline Sort by: phone \newline Mallory 0810001111 \newline Alice 0819998888} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#4}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include\textless{}stdio.h\textgreater{} \newline int main() \newline \{ \newline int n,i=0,count=0; \newline char a{[}80{]},b{[}80{]},c; \newline printf("First string:"); \newline c = getchar(); \newline while ((i\textless{}80) \&\& (c != '\textbackslash{}n'))\{a{[}i{]} = c; i++; c = getchar();\} \newline a{[}i{]} = '\textbackslash{}0'; \newline n = i; \newline printf("Second string:"); \newline i=0; \newline c = getchar(); \newline while ((i\textless{}80) \&\& (c != '\textbackslash{}n'))\{b{[}i{]} = c; i++; c = getchar();\} \newline b{[}i{]} = '\textbackslash{}0'; \newline for( i=n-1 ; i\textgreater{}=0 ;i-{}- ) \newline \{ \newline if(a{[}i{]}+32 != b{[}i{]} \&\& a{[}i{]} != b{[}i{]}+32 \&\& a{[}i{]} != b{[}i{]}) count++; \newline \} \newline printf("\%d",count); \newline return 0; \newline \} \newline \newline First string:hallo \newline Second string:hello \newline 1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{File I/O}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}stdlib.h\textgreater{} \newline int calculateAge(int year); \newline struct birthdate\{ \newline int day; \newline int month; \newline int year; \newline \}; \newline struct student\{ \newline int id; \newline char name{[}100{]}; \newline struct birthdate information; \newline \}; \newline struct student student\_infor; \newline int main()\{ \newline int id, day, month, year, age; \newline char name{[}80{]}; \newline FILE {\emph{inFile; \newline inFile = fopen("student.txt", "r"); \newline if (inFile == NULL) \{ \newline printf("Failed to open the file.\textbackslash{}n"); \newline exit(1); \newline \} \newline while (fscanf(inFile, "\%d \%s \%d \%d \%d", \&student\_infor.id, \&student\_infor.name, \seqsplit{\&student\_infor.information.day}, \seqsplit{\&student\_infor.information.month}, \seqsplit{\&student\_infor.information.year)} != EOF)\{ \newline printf("Read \%d \%s \%d \%d \%d\textbackslash{}n", student\_infor.id, student\_infor.name, \seqsplit{student\_infor.information.day}, \seqsplit{student\_infor.information.month}, \seqsplit{student\_infor.information.year);} \newline /}} copy the data into the Student struct */ \newline \} \newline age = \seqsplit{calculateAge(student\_infor}.information.year); \newline fclose(inFile); \newline inFile = fopen("student\_age.txt","w"); \newline fprintf(inFile,"Student ID: \%d",student\_infor.id); \newline fprintf(inFile,"\textbackslash{}nName: \%s",student\_infor.name); \newline fprintf(inFile,"\textbackslash{}nBirthdate: \%d/\%d/\%d",student\_infor.information.day,student\_infor.information.month,student\_infor.information.year); \newline fprintf(inFile,"\textbackslash{}nAge: \%d",age); \newline fclose(inFile); \newline \} \newline \newline int calculateAge(int year)\{ \newline int x = 2018 - year; \newline return x; \newline \} \newline \newline Read 31257 Alice 14 12 1993} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{File I/O \#2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}stdlib.h\textgreater{} \newline float covert(float x); \newline int main()\{ \newline float f{[}6{]}; \newline float c{[}6{]}; \newline FILE {\emph{Data; \newline Data = fopen("f.txt","r"); \newline if (Data == NULL)\{ \newline printf("ERROR"); \newline exit(1); \newline \} \newline for (int x = 0;x \textless{} 6;x++)\{ \newline fscanf(Data,"\%f",\&f{[}x{]}); \newline \} \newline fclose(Data); \newline Data =fopen("c.txt","w"); \newline for (int x = 0;x \textless{} 6;x++)\{ \newline fprintf(Data,"\%f",covert(f{[}x{]})); \newline if (x \textless{} 5)\{ \newline fprintf(Data,"\textbackslash{}n"); \newline \} \newline \} \newline fclose(Data); \newline printf("finished"); \newline \} \newline float covert(float x)\{ \newline float z; \newline z = ((x -32.0) }} (1.8)); \newline return z; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline int main()\{ \newline int x,a,b,c; \newline printf("a"); \newline scanf("\%d",\&x); \newline a = x / 2;int ax = 0;int ay = a - 2;int bx = x - 2;int by = 1; \newline for (int y = 0;y \textless{} x/2;y++)\{ \newline for(int alpha = 0;alpha \textless{} ax;alpha++)\{ \newline printf("1"); \newline \} \newline if (ax != a)\{ \newline printf("2"); \newline \} \newline for (int beta = bx;beta \textgreater{} 0;beta-{}- )\{ \newline printf("1"); \newline \} \newline if (ax != a)\{ \newline printf("2"); \newline \} \newline for(int alpha = 0;alpha \textless{} ax;alpha++)\{ \newline printf("1"); \newline \} \newline bx -= 2; \newline ax++; \newline printf("\textbackslash{}n"); \newline \} \newline for (int alpha = 0;alpha \textless{} a;alpha++)\{ \newline printf("1"); \newline \} \newline printf("3"); \newline for (int alpha = 0;alpha \textless{} a;alpha++)\{ \newline printf("1"); \newline \} \newline printf("\textbackslash{}n"); \newline for (int y = 0;y \textless{} x/2;y++)\{ \newline for(int alpha = ay;alpha \textgreater{}= 0;alpha-{}-)\{ \newline printf("1"); \newline \} \newline if (ay != a)\{ \newline printf("2"); \newline \} \newline for (int beta = 0;beta \textless{} by;beta++ )\{ \newline printf("1"); \newline \} \newline if (ay != a)\{ \newline printf("2"); \newline \} \newline for(int alpha = ay;alpha \textgreater{}= 0;alpha-{}-)\{ \newline printf("1"); \newline \} \newline by += 2; \newline ay-{}-; \newline printf("\textbackslash{}n"); \newline \} \newline \} \newline \newline a5 \newline 21112 \newline 12121 \newline 11311 \newline 12121 \newline 21112} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#8}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include\textless{}stdio.h\textgreater{} \newline int main() \newline \{ \newline int age\_12,sum=0,i,j=0,a{[}1000{]}; \newline typedef struct TitleNameAge \newline \{ \newline char tt{[}100{]}; \newline char name{[}80{]}; \newline int age; \newline \}data; \newline data A; \newline printf("Input your title:"); \newline scanf(" \%s",\&A.tt); \newline printf("Input your Name:"); \newline scanf(" \%s",\&A.name); \newline printf("Input your Age:"); \newline scanf(" \%d",\&A.age); \newline age\_12 = A.age - 12; \newline if(age\_12 \textgreater{}12) age\_12 = 12; \newline printf("Hello "); \newline if(A.age \textgreater{}= 20 ) printf("\%s.",A.tt); \newline printf("\%s",A.name); \newline for( i=1 ; i\textless{}=A.age ; i++) \{sum+=i;\} \newline printf("\textbackslash{}nSum of the number 1 to Age: \%d\textbackslash{}n",sum); \newline for( i=1 ; i\textless{}A.age ; i++) \newline \{ \newline if( i\%3 == 0 || i\%5 == 0 ) \newline \{ \newline a{[}j{]} = i; \newline j++; \newline \} \newline \} \newline a{[}j{]} = '\textbackslash{}0'; \newline int n=j; \newline printf("The multiples of 3 or 5: "); \newline for( j=0 ; j\textless{}=n-1 ; j++) \newline \{ \newline if(j!=n-1) \newline printf("\%d,",a{[}j{]}); \newline else printf("\%d",a{[}j{]}); \newline \} \newline for(i=1 ; i\textless{}13 ; i++) \newline \{ \newline printf("\textbackslash{}n\%dx\%d = \%d",age\_12,i,age\_12*i); \newline \} \newline return 0; \newline \} \newline \newline Input your title:mr \newline Input your Name:phon \newline Input your Age:16 \newline Hello phon \newline Sum of the number 1 to Age: 136 \newline The multiples of 3 or 5: 3,5,6,9,10,12,15 \newline 4x1 = 4 \newline 4x2 = 8 \newline 4x3 = 12 \newline 4x4 = 16 \newline 4x5 = 20 \newline 4x6 = 24 \newline 4x7 = 28 \newline 4x8 = 32 \newline 4x9 = 36 \newline 4x10 = 40 \newline 4x11 = 44 \newline 4x12 = 48} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#7}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include\textless{}stdio.h\textgreater{} \newline int main() \newline \{ \newline int i=0; \newline char a{[}80{]},c; \newline printf("Input your number: "); \newline c = getchar(); \newline while( i\textless{}80 \&\& c != '\textbackslash{}n') \newline \{ \newline a{[}i{]} = c; \newline i++; \newline c = getchar(); \newline \} \newline a{[}i{]} = '\textbackslash{}0'; \newline for( i=i-1 ; i\textgreater{}=0 ; i-{}-) printf("\%c",a{[}i{]}); \newline return 0; \newline \} \newline \newline Input your number: 12345 \newline 54321} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#5}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include\textless{}stdio.h\textgreater{} \newline int main() \newline \{ \newline int N,i=0,sum=0; \newline printf("SIZE: "); \newline scanf("\%d",\&N); \newline int a{[}N{]},b{[}N{]}; \newline printf("Please enter number such as a={[}a1,a2,..{]}: "); \newline for(i=0 ; i\textless{}N ;i++) \{ scanf("\%d",\&a{[}i{]}); \} \newline printf("Please enter number such as b={[}b1,b2,..{]}: "); \newline for(i=0 ; i\textless{}N ;i++) \{ scanf("\%d",\&b{[}i{]}); \} \newline for(i=0 ; i\textless{}N ;i++) \{ sum += a{[}i{]}*b{[}i{]}; \} \newline printf("Dot-product = \%d",sum); \newline return 0; \newline \} \newline \newline SIZE: 4 \newline Please enter number such as a={[}a1,a2,..{]}: 1 2 3 4 \newline Please enter number such as b={[}b1,b2,..{]}: 1 2 3 4 \newline Dot-product = 30} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{GCD without loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \newline int gcd(int a, int b) \newline \{ \newline if (b == 0) \newline return a; \newline return gcd(b, a \% b); \newline \} \newline \newline \newline int main() \newline \{ \newline int a,b; \newline printf("Input two number: "); \newline scanf("\%d\%d",\&a,\&b); \newline printf("The GCD of \%d and \%d is \%d",a,b,gcd(a,b)); \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#3}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#define pie 3.14 \newline float \seqsplit{Circumferencefunction(int} a,float {\emph{b); \newline float Areafunction(int a,float }}b); \newline int main()\{ \newline float {\emph{Area,}}Circumference,a,b;int x; \newline Area = \&a; \newline Circumference = \&b; \newline scanf("\%d",\&x); \newline Circumferencefunction(x,Circumference); \newline Areafunction(x,Area); \newline printf("\%.2f \%.2f",{\emph{Circumference,}}Area); \newline \} \newline float \seqsplit{Circumferencefunction(int} a,float {\emph{b)\{ \newline }}b = 2 {\emph{ pie }} a; \newline \} \newline \newline float Areafunction(int a,float {\emph{b)\{ \newline }}b = pie {\emph{ a }} a; \newline \} \newline \newline 3 \newline 18.84 28.26} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Extralab\#1}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include\textless{}stdio.h\textgreater{} \newline int main() \newline \{ \newline int a{[}32{]} = \{0,1\},i; \newline for(i=1 ; i\textless{}31 ; i++) \newline \{ \newline a{[}i+1{]} = a{[}i{]} + a{[}i-1{]}; \newline printf("\%d",a{[}i-1{]}); \newline if(i != 30) \newline printf(","); \newline \} \newline return 0; \newline \} \newline \newline 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 \newline 46368 75025 121393 196418 317811 514229} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Monster game(evolved one)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}string.h\textgreater{} \newline struct monster\{ \newline char name{[}80{]}; \newline int attack; \newline int hp; \newline \}monsters{[}3{]}; \newline \newline struct monster monsters{[}3{]} = \{\{"bone",20,50\},\{"snot",30,100\},\{"plague",50,70\}\}; \newline int PlayerHP = 100; \newline int {\emph{current\_playerHP; \newline int }}current\_monsterHP; \newline int main()\{ \newline char choice; \newline int dmg; \newline int Remaining; \newline current\_playerHP = \&PlayerHP; \newline int loop = 1; \newline char choose{[}7{]} = \{0\}; \newline while (loop == 1)\{ \newline printf("\textbackslash{}nEnter the 1st character of Monster's name: "); \newline scanf("\%s",\&choose); \newline printf("Enter the attack power from 1 to 100: "); \newline scanf("\%d",\&dmg); \newline if(strcmp(choose,monsters{[}0{]}.name) == 0)\{ \newline printf("Monster: \%s",monsters{[}0{]}.name); \newline current\_monsterHP = \&monsters{[}0{]}.hp; \newline current\_playerHP = \&PlayerHP; \newline if (dmg \textgreater{} {\emph{current\_monsterHP)\{ \newline }}current\_monsterHP = 0; \newline printf("\textbackslash{}nHP: \%d",{\emph{current\_monsterHP); \newline printf("\textbackslash{}nYour HP: \%d",}}current\_playerHP); \newline printf("\textbackslash{}nYou Won"); \newline \} \newline else if(monsters{[}0{]}.attack \textgreater{}= {\emph{current\_playerHP)\{ \newline printf("\textbackslash{}nHP: \%d",}}current\_monsterHP); \newline {\emph{current\_playerHP = 0; \newline printf("\textbackslash{}nYour HP: \%d",}}current\_playerHP); \newline printf("\textbackslash{}nYou Lose"); \newline break; \newline \} \newline else\{ \newline {\emph{current\_monsterHP -= dmg; \newline printf("\textbackslash{}nHP: \%d",}}current\_monsterHP); \newline {\emph{current\_playerHP -= monsters{[}0{]}.attack; \newline printf("\textbackslash{}nYour HP: \%d",}}current\_playerHP); \newline \} \newline \} \newline else if(strcmp(choose,monsters{[}1{]}.name) == 0)\{ \newline printf("Monster: \%s",monsters{[}0{]}.name); \newline current\_monsterHP = \&monsters{[}1{]}.hp; \newline current\_playerHP = \&PlayerHP; \newline printf("\textbackslash{}nCurrent HP: \%d",{\emph{current\_monsterHP); \newline printf("\textbackslash{}nAttack power: \%d",dmg); \newline if (dmg \textgreater{} }}current\_monsterHP)\{ \newline {\emph{current\_monsterHP = 0; \newline printf("\textbackslash{}nHP: \%d",}}current\_monsterHP); \newline printf("\textbackslash{}nYour HP: \%d",{\emph{current\_playerHP); \newline printf("\textbackslash{}nYou Won"); \newline \} \newline else if(monsters{[}1{]}.attack \textgreater{}= }}current\_playerHP)\{ \newline printf("\textbackslash{}nHP: \%d",{\emph{current\_monsterHP); \newline }}current\_playerHP = 0; \newline printf("\textbackslash{}nYour HP: \%d",{\emph{current\_playerHP); \newline printf("\textbackslash{}nYou Lose"); \newline break; \newline \} \newline else\{ \newline }}current\_monsterHP -= dmg; \newline printf("\textbackslash{}nHP: \%d",{\emph{current\_monsterHP); \newline }}current\_playerHP -= monsters{[}1{]}.attack; \newline printf("\textbackslash{}nYour HP: \%d",{\emph{current\_playerHP); \newline \} \newline \} \newline else if(strcmp(choose,monsters{[}2{]}.name) == 0)\{ \newline printf("Monster: \%s",monsters{[}0{]}.name); \newline current\_monsterHP = \&monsters{[}2{]}.hp; \newline current\_playerHP = \&PlayerHP; \newline printf("\textbackslash{}nCurrent HP: \%d",}}current\_monsterHP); \newline printf("\textbackslash{}nAttack power: \%d",dmg); \newline if (dmg \textgreater{} {\emph{current\_monsterHP)\{ \newline }}current\_monsterHP = 0; \newline printf("\textbackslash{}nHP: \%d",{\emph{current\_monsterHP); \newline printf("\textbackslash{}nYour HP: \%d",}}current\_playerHP); \newline printf("\textbackslash{}nYou Won"); \newline \} \newline else if(monsters{[}2{]}.attack \textgreater{}= {\emph{current\_playerHP)\{ \newline printf("\textbackslash{}nHP: \%d",}}current\_monsterHP); \newline {\emph{current\_playerHP = 0; \newline printf("\textbackslash{}nYour HP: \%d",}}current\_playerHP); \newline printf("\textbackslash{}nYou Lose"); \newline break; \newline \} \newline else\{ \newline {\emph{current\_monsterHP -= dmg; \newline printf("\textbackslash{}nHP: \%d",}}current\_monsterHP); \newline {\emph{current\_playerHP -= monsters{[}2{]}.attack; \newline printf("\textbackslash{}nYour HP: \%d",}}current\_playerHP); \newline \} \newline \} \newline else\{ \newline printf("Invalid Input"); \newline \} \newline \} \newline \} \newline \newline Enter the 1st character of Monster's name: bone \newline Enter the attack power from 1 to 100: 2 \newline Monster: bone \newline HP: 48 \newline Your HP: 80} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{find min,range,mean(pointer)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline float findMean(int {\emph{num)\{ \newline float a=0; \newline for (int x = 0; x \textless{} 5;x++)\{ \newline a += }}num + x; \newline \} \newline a = a / 5; \newline return a; \newline \} \newline int findMin(int {\emph{num)\{ \newline int a = (}}num); \newline for (int x = 0;x \textless{}= 4;x++)\{ \newline if (a \textgreater{} {\emph{(num + x))\{ \newline a = }}(num + x); \newline \} \newline \} \newline return a; \newline \} \newline int findRange(int num{[}{]},int z)\{ \newline int a = ({\emph{num); \newline for (int x = 0;x \textless{} 4;x++)\{ \newline if (a \textless{}= }}(num + x))\{ \newline a = *(num + x); \newline \} \newline \} \newline int c = a - z; \newline return c; \newline \} \newline int main()\{ \newline int num{[}5{]}; \newline printf("Enter 5 integers: "); \newline scanf("\%d \%d \%d \%d \%d",\&num{[}0{]},\&num{[}1{]},\&num{[}2{]},\&num{[}3{]},\&num{[}4{]}); \newline printf("Mean: \%.3f and Min: \%d and Range: \%d",findMean(num),findMin(num),findRange(num,findMin(num))); \newline \} \newline \newline Enter 5 integers: 39 100 -8 7 66 \newline Mean: 41.000 and Min: -8 and Range: 108} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Lab3 wk11}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#define N 4 \newline \newline int gcd(int num1, int num2) \{ \newline // Parameter to store the GCD \newline int result; \newline int loop1 = 1; \newline while(num1 != num2)\{ \newline if(num1 \textgreater{} num2) \newline num1 -= num2; \newline else \newline num2 -= num1; \newline \} \newline return num1; \newline \} \newline \newline int main() \{ \newline int num{[}N{]}; // Input numbers \newline int result; // GCD of the input numbers \newline \newline printf("Enter \%d numbers: ", N); \newline for (int i=0 ; i\textless{}N ; i++) \{ \newline scanf("\%d", \&num{[}i{]}); \newline \} \newline result = gcd(num{[}0{]},num{[}1{]}); \newline result = gcd(result,num{[}2{]}); \newline result = gcd(result,num{[}3{]}); \newline printf("GCD of "); \newline for (int i=0 ; i\textless{}N ; i++) \{ \newline printf("\%d ", num{[}i{]}); \newline \} \newline printf("is \%d\textbackslash{}n", result); \newline \newline return 0; \newline \} \newline \newline Enter 4 numbers: 122 134 153 187 \newline GCD of 122 134 153 187 is 1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{lab3 wk10}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}time.h\textgreater{} \newline \#include \textless{}stdlib.h\textgreater{} \newline int check(int a,int x)\{ \newline int z; \newline if (a \textgreater{} x)\{ \newline z = 1; \newline \} \newline else if(a \textless{} x)\{ \newline z = 2; \newline \} \newline else\{ \newline z = 3; \newline \} \newline return z; \newline \} \newline int main()\{ \newline srand(time(NULL)); \newline int loop = 1,x,y,count = 10,random = rand() \% 100 + 1; \newline while (count != 0)\{ \newline //printf("\%d ",random); \newline printf("Enter your guess: "); \newline scanf("\%d",\&y); \newline x = check(y,random); \newline if (x == 1)\{ \newline printf("Wrong number :( Your guess was too high.\textbackslash{}n"); \newline count-{}-; \newline printf("You have \%d guesses left. Try again\textbackslash{}n\textbackslash{}n",count); \newline \} \newline else if (x == 2)\{ \newline printf("Wrong number :( Your guess was too low.\textbackslash{}n"); \newline count-{}-; \newline printf("You have \%d guesses left. Try again\textbackslash{}n\textbackslash{}n",count); \newline \} \newline else\{ \newline printf("Hooray, you have won!\textbackslash{}n"); \newline break; \newline \} \newline \} \newline if (count == 0)\{ \newline printf("Sorry, you lose\textbackslash{}n"); \newline \} \newline \} \newline \newline Enter your guess: 1 \newline Wrong number :( Your guess was too low. \newline You have 9 guesses left. Try again} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{bonuslab wk9}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \newline int main()\{ \newline int rows,cols,loop1 = 1; \newline printf("Enter the number of rows and columns: "); \newline scanf("\%d \%d",\&rows,\&cols); \newline while (loop1 == 1)\{ \newline if (rows != cols)\{ \newline loop1 = 0; \newline printf("That matrix must be a square matrix."); \newline \} \newline else\{ \newline int matrix{[}rows{]}{[}cols{]}; \newline int tmatrix{[}rows{]}{[}cols{]}; \newline int count1 = 0,count2 = 0; \newline for (int x = 0;x \textless{} rows;x++)\{ \newline for (int y = 0;y \textless{} cols;y++)\{ \newline printf("Enter element \%d,\%d: ",x,y); \newline scanf("\%d",\&matrix{[}x{]}{[}y{]}); \newline tmatrix{[}count1{]}{[}count2{]} = matrix{[}x{]}{[}y{]}; \newline count1++; \newline if (count1 \textgreater{}= rows)\{ \newline count2++; \newline count1 = 0; \newline \} \newline \} \newline \} \newline int check = 0; \newline for (int xt = 0;xt \textless{} rows;xt++)\{ \newline for (int yt = 0;yt \textless{} cols;yt++)\{ \newline if (matrix{[}xt{]}{[}yt{]} != tmatrix{[}xt{]}{[}yt{]})\{ \newline check = 1; \newline break; \newline \} \newline \} \newline \} \newline if (check == 1)\{ \newline printf("The matrix is not symmetric."); \newline \} \newline else\{ \newline printf("The matrix is symmetric."); \newline \} \newline loop1 = 0; \newline \} \newline \} \newline \} \newline \newline Enter the number of rows and columns: 3 3 \newline Enter element 0,0: 1 \newline Enter element 0,1: 1 \newline Enter element 0,2: 1 \newline Enter element 1,0: 1 \newline Enter element 1,1: 1 \newline Enter element 1,2: 1 \newline Enter element 2,0: 1 \newline Enter element 2,1: 1 \newline Enter element 2,2: 1 \newline The matrix is symmetric.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}