April 8, 2015

Sample Program (HTML)2ndyear/Tri-3rdsem

<html>
<body>
<head>
<table>
<body style="background-color:#87CEFA;">
<tr>
<td width="20%"></td>
<a name="top">
<td><center><h1><u>C Programming</u></center><br>
<center>
by:<b>Gene Liza Cordova</b><br></a></center>
<ul>
<li><a href ="#one">History of C</a></li><br><br>
<li><a href ="#two">Layout of C</a></li><br><br>
<li><a href ="#three">Data Types</a></li><br><br>
<li><a href ="#four">Sample program</a></li><br><br>
</ul>




<hr>
<a name="one"><font size="5">History of C</font></a>
<hr>
<p align="justify">A Brief History of C
C is a general-purpose language which has been closely associated with the UNIX operating system for which it was developed - since the system and most of the programs that run it are written in C.
Many of the important ideas of C stem from the language BCPL, developed by Martin Richards. The influence of BCPL on C proceeded indirectly through the language B, which was written by Ken Thompson in 1970 at Bell Labs, for the first UNIX system on a DEC PDP-7. BCPL and B are "type less" languages whereas C provides a variety of data types.
In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming Language by Kernighan & Ritchie caused a revolution in the computing world.
In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or "ANSI C", was completed late 1988.
A Rough Guide to Programming Languages is available on-line for those of you that are interested.
</p>

<a href ="#top">back to top</a><br><br>



<hr><a name="two"><font size="5">Layout of C</font></a><hr>
<p align="justify">C is an imperative (procedural) language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support. C was therefore useful for many applications that had formerly been coded in assembly language, such as in system programming.
Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant and portably written C program can be compiled for a very wide variety of computer platforms and operating systems with few changes to its source code. The language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers.
</p>

<a href ="#top">back to top</a><br><br>




<hr>
<a name="three"><font size="5">Data Types</font></a>
<hr>
<b>Objectives</b><br>
<br>Having read this section you should be able to:
<br>
declare (name) a local variable as being one of C's five data types
initialise local variables
perform simple arithmetic using local variables
Now we have to start looking into the details of the C language. How easy you find the rest of this section will depend on whether you have ever programmed before - no matter what the language was. There are a great many ideas common to programming in any language and C is no exception to this rule.
So if you haven't programmed before, you need to take the rest of this section slowly and keep going over it until it makes sense. If, on the other hand, you have programmed before you'll be wondering what all the fuss is about It's a lot like being able to ride a bike!
The first thing you need to know is that you can create variables to store values in. A variable is just a named area of storage that can hold a single value (numeric or character). C is very fussy about how you create variables and what you store in them. It demands that you declare the name of each variable that you are going to use and its type, or class, before you actually try to do anything with it.
In this section we are only going to be discussing local variables. These are variables that are used within the current program unit (or function) in a later section we will looking at global variables - variables that are available to all the program's functions.
There are five basic data types associated with variables:
<br>
<b><br>int </b>- integer: a whole number.
<b><br>float</b> - floating point value: ie a number with a fractional part.
<b><br>double</b> - a double-precision floating point value.
<b><br>char</b> - a single character.
<b><br>void </b>- valueless special purpose type which we will examine closely in later sections.<br><br>
One of the confusing things about the C language is that the range of values and the amount of storage that each of these types takes is not defined. This is because in each case the 'natural' choice is made for each type of machine. You can call variables what you like, although it helps if you give them sensible names that give you a hint of what they're being used for - names like sum, total, average and so on. If you are translating a formula then use variable names that reflect the elements used in the formula. For example, 2(r (that should read as "2 pi r" but that depends upon how your browser has been set-up) would give local variables names of pi and r. Remember, C programmers tend to prefer short names!
<br>
<b>Note:</b>all C's variables must begin with a letter or a "_" (underscore) character.
</p>

<p align="justify">Microsoft's webmail isn't the only service that's changed: A dropdown next to the main icon in the Outlook.com interface offers access to other
 suite members, similar to the way Apple's iCloud Web apps do, with brightly colored Metro-style tiles. These include People, Mail, SkyDrive, and, eventually, Calendar, though
the Calendar sub-site still has the old Hotmail design at the time of my testing. The integration between these services is much tighter, especially with the new Microsoft account,
which will tie together not just these, but also will work with your Xbox Live account if you have one, and your Windows 8 PC's default apps.
<br><br>

<b>Integer Number Variables</b><br></b><br> <br>

The first type of variable we need to know about is of class type int - short for integer. An int variable can store a value in the range -32768 to +32767. You can think of it as a largish positive or negative whole number: no fractional part is allowed. To declare an int you use the instruction:
int variable name;
<br>
For example:
<br>int a;
declares that you want to create an int variable called a.
To assign a value to our integer variable we would use the following C statement:
<br>a=10;

<br>The C programming language uses the "=" character for assignment. A statement of the form a=10; should be interpreted as take the numerical value 10 and store it in a memory location associated with the integer variable a. The "=" character should not be seen as an equality otherwise writing statements of the form:
a=a+10;

</p>
<a href ="#top">back to top</a>


<hr><a name="four"><font size="5"><b>Sample Program</b></font></a><hr>
<p align="justify"><b>Your First Program</b><br>

<br><b>Objectives</b><br>

Having read this section you should have an understanding of:<br>

a pre-processor directive that must be present in all your C programs.
a simple C function used to write information to your screen.
how to add comments to your programs
Now that you've seen the compiler in action it's time for you to write your very own first C program. You can probably guess what it's going to be - the program that everyone writes just to check they understand the very, very, very basics of what is going on in a new language.
<br>
Yes - it's the ubiquitous "Hello World" program. All your first program is going to do is print the message "Hello World" on the screen.
<br>
The program is a short one, to say the least. Here it is:
<br>
<br>
#include $$$$stdio.h&&&&
<br>
main()
<br>
{
<br>
printf("Hello World\n");
<br>
}
<br>
[program]
<br><br>

<br>
The first line is the standard start for all C programs - main(). After this comes the program's only instruction enclosed in curly brackets {}. The curly brackets mark the start and end of the list of instructions that make up the program - in this case just one instruction.

Notice the semicolon marking the end of the instruction. You might as well get into the habit of ending every C instruction with a semicolon - it will save you a lot of trouble! Also notice that the semicolon marks the end of an instruction - it isn't a separator as is the custom in other languages.

If you're puzzled about why the curly brackets are on separate lines I'd better tell you that it's just a layout convention to help you spot matching brackets. C is very unfussy about the way you lay it out. For example, you could enter the Hello World program as:

main(){printf("Hello World\n");}

but this is unusual.

The printf function does what its name suggest it does: it prints, on the screen, whatever you tell it to. The "\n" is a special symbols that forces a new line on the screen.

OK, that's enough explanation of our first program! Type it in and save it as Hello.c. Then use the compiler to compile it, then the linker to link it and finally run it. The output is as follows:

Hello World
</p>

<a href ="#top">back to top</a><br><br>
<td width="20%"></td>
</tr>



</div>

</td>
</table>
</body>
</html>





Thanks : http://www.quackit.com/html/codes/html_background_codes.cfm

No comments: