diff options
Diffstat (limited to 'reference/C/PROBLEMS/problems.html')
-rw-r--r-- | reference/C/PROBLEMS/problems.html | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/reference/C/PROBLEMS/problems.html b/reference/C/PROBLEMS/problems.html new file mode 100644 index 0000000..6455681 --- /dev/null +++ b/reference/C/PROBLEMS/problems.html @@ -0,0 +1,242 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.5 [en] (X11; I; Linux 2.0.36 i586) [Netscape]"> + <title>C programming problems</title> +</head> +<body bgcolor="#FFFFCC"> + +<hr> +<center> +<h1> +C programming problems</h1></center> + +<hr> +<p>Here are few problems to try out your C skills on. +<hr> +<dl compact> +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Produce a multiplication table. Top left hand corner will show 1x1 and +bottom right shows 12x12, as below.</dd> + +<pre> + 1 2 3 4 5 6 7 8 9 10 11 12 + 2 4 6 8 10 12 14 16 18 20 22 24 + 3 6 9 12 15 18 21 24 27 30 33 36 + 4 8 12 16 20 24 28 32 36 40 44 48 + 5 10 15 20 25 30 35 40 45 50 55 60 + 6 12 18 24 30 36 42 48 54 60 66 72 + 7 14 21 28 35 42 49 56 63 70 77 84 + 8 16 24 32 40 48 56 64 72 80 88 96 + 9 18 27 36 45 54 63 72 81 90 99 108 + 10 20 30 40 50 60 70 80 90 100 110 120 + 11 22 33 44 55 66 77 88 99 110 121 132 + 12 24 36 48 60 72 84 96 108 120 132 144</pre> + +<dt> +<img SRC="computer.gif" ><a href="times1.c">Answer 1</a></dt> + +<dt> +<img SRC="computer.gif" ><a href="times2.c">Answer 2</a> +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Produce an Ascii convertion table.</dd> + +<dt> +<img SRC="computer.gif" height=44 width=40><a href="ascii1.c">Answer 1</a></dt> + +<dt> +<img SRC="computer.gif" height=44 width=40><a href="ascii2.c">Answer 2 </a> +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Convert unix files to DOS format.</dd> + +<dd> +Unix records are terminated with x'0a'</dd> + +<dd> +DOS records are terminated with x'0d0a'</dd> + +<dt> +<img SRC="computer.gif" ><a href="unix2dos.c">Answer</a> +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +'for' problem. Count from 1 to 32 and list the range of unsigned integer +numbers that can be stored in each collection of bits. I.E 8 bits can hold +the range 0 to 255.</dd> + +<dt> +<img SRC="computer.gif" ><a href="bits.c">Answer</a> +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Random numbers. Produce a sequence of six random numbers between 1 and +49. These can then be used to play the National lottery (in England). The +odds on getting the right numbers are 13,983,816 to 1 - GOOD LUCK SUCKER.</dd> + +<dt> +<img SRC="computer.gif" ><a href="lotto1.c">Answer</a> should look like:</dt> + +<pre> Possible winning ticket numbers are 7 8 9 33 34 43</pre> + +<hr> +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Take the previous 'lotto' program and add code so duplicate numbers are +filtered out and the results are sorted (use <a href="../FUNCTIONS/qsort.html">qsort</a>).</dd> + +<dt> +<img SRC="computer.gif" ><a href="lotto2.c">Answer</a> +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Here is a problem you can solve with an integer array. Generate the Fibonacci +sequence. Starting with 0, 1 add them up then take the result and add it +to the last number and repeat.</dd> + +<dt> +<img SRC="computer.gif" ><a href="array_prob.c">Answer</a> should look +like:</dt> + +<pre>0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181</pre> + +<dt> +<img SRC="computer.gif" ><a href="../CONTRIB/OR_PRACTICAL_C/05_1.c">Answer</a> +taken from 'Practical C' from O'Reilly and Associates. +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Functions - write a program that calls bignum() and littlenum() which determine, +respectively, the highest and the smallest of a sequecnce of numbers read +in from the terminal.</dd> + +<dt> +<img SRC="computer.gif" ><a href="numtest.c">Answer</a> +<hr></dt> + +<p><br><a NAME="struct"></a> +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Structures - Use structures to add two fractions together.</dd> + +<dt> +<img SRC="computer.gif" ><a href="fractions.c">Answer</a> +<hr></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Write a calendar program</dd> + +<dt> +<img SRC="computer.gif" ><a href="calender.c">Answer</a></dt> + +<p><br> +<hr> +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Print the name of the program thats executing.</dd> + +<dt> +<img SRC="computer.gif" ><a href="../EXAMPLES/prog_name.c">Answer</a> +<hr><a NAME="hexdump"></a></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Produce a program that will display a file in hex format as below. Most +versions of Unix have 'od' but this dump format is more usefull.</dd> + +<pre> 20 2A 20 68 65 78 5F 63 68 61 72 28 63 68 61 72 * hex_char(char + 20 2A 70 6F 73 69 74 69 6F 6E 2C 20 63 68 61 72 *position, char + 20 63 29 0A 20 20 20 7B 0A 20 20 20 73 70 72 69 c). {. spri + 6E 74 66 28 70 6F 73 69 74 69 6F 6E 2C 20 22 25 ntf(position, "% + 30 32 58 20 22 2C 20 63 29 3B 20 0A 0A 09 09 09 02X ", c); .....</pre> + +<dt> +<img SRC="computer.gif" ><a href="hexdump1.c">Answer</a> +<hr><a NAME="yesterday"></a></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Print yesterdays date. You can use the ANSI standard functions 'time' and +'ctime'. An example of the O/P from my program is.</dd> + +<pre> Fri Mar 17 18:46:47 1995</pre> + +<dt> +<img SRC="computer.gif" ><a href="yesterday.c">Answer</a> +<hr><a NAME="binary"></a></dt> + +<dt> +<img SRC="whiteball.gif" ></dt> + +<dd> +Display a byte in binary format. For example:</dd> + +<pre> 55 == 00110111</pre> +Things like <b><< <<= &</b> can be used to solve this problem. +<dt> +<img SRC="computer.gif" ><a href="binary_op.c">Answer</a></dt> +</dl> + +<hr> +<center><table BORDER=2 WIDTH="80%" BGCOLOR="#FFFFF0" > +<tr ALIGN=CENTER> +<td WIDTH="25%"><a href="../cref.html" target="_top">Top</a></td> + +<td WIDTH="25%"><a href="../master_index.html" target="_top">Master Index</a></td> + +<td WIDTH="25%"><a href="../SYNTAX/keywords.html" target="_top">C Keywords</a></td> + +<td WIDTH="25%"><a href="../FUNCTIONS/funcref.htm" target="_top">Functions</a></td> +</tr> +</table></center> + +<p> +<hr> +<address> +Martin Leslie<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> + +</body> +</html> |