Saturday, July 25, 2015

Introduction to HTML


WHAT IS HTML?
HTML provides a way of displaying Web pages with text and images or multimedia content. HTML is not a programming language, but a markup language. An HTML file is a text file containing small markup tags. The markup tags tell the Web browser, such as Mozila Firefox or Google Chrome, how to display the page. An HTML file must have an htm or html file extension. HTML stands for HyperText Markup Language.

HTML pages are of two types:

Static Pages - Static pages, as the name indicates, comprise static content (text or images). So you can only see the contents of a web page without being able to have any interaction with it.

Dynamic Pages - Dynamic pages are those where the content of the web page depend on user input. So interaction with the user is required in order to display the web page. For example, consider a web page which requires a number to be entered from the user in order to find out if it is even or odd. When the user enters the number and clicks on the appropriate button, the number is sent to the web server, which in turn returns the result to the user in an HTML page.


Tags and Elements
A tag is a bit of text that acts as a point demarcation. To create a tag, HTML gives certain characters special meaning: the angle brackets < and >.
            Putting characters within angle brackets creates a tag.


There are two tags: Start tag or opening tag and end tag or closing tag. An end tag always matches a start tag, except that it has an extra forward slash after the opening angle bracket.

The combination of a start and end tags define an element. Everything between the two tags is referred to as the contents of the element.


Attribute
Attributes provide additional information about the contents of an element. They appear on the opening tag of the element and are made up of two parts: - a name and a value, separated by an equals sign.


The attribute name indicates what kind of extra information you are supplying about the element's content. It should be written in lowercase.

The value is the information or setting for the attribute. It should be placed in double quotes. Different attributes can have different values.

In this example an attribute called lang is used to indicate the language used in this element. The value of this attribute on this page specifies it is in US English.

Note: - HTML5 allows you to use uppercase attribute names and omit the quote marks, but this is not recommended.

HTML Tag - <HTML> is a starting tag. To delimit the text inside, add a closing tag by adding a forward slash “/” to the starting tag. Most but not all tags have a closing tag. It is necessary to write the code for an HTML page between <HTML> and </HTML>. This <HTML> tells the browser is 'this is the start of an HTML document' and </HTML> 'this is the end of an HTML document'.

<html>
...........................
...............................
.........................

</html>

Head Tag - Before the <body> element you will often see a <head> element. This contains information about the page, rather than information that is shown within the main part of the browser. You will usually find a <title> element inside the <head> element. <head> is opening head tag and </head> is closing head tag.

<html>
            <head>
                        <title> Hello </title>
            </head>
</html>


Title Tag: - The contents of the <title> element are either shown in the top of the browser, above where you usually type in the URL of the page you want to visit, or on the tab for that page (if your browser uses tabs to allow you to view multiple pages at the same time). <title> is opening title tag and </title> closing title tag.

<html>
            <head>
                        <title> Hello </title>
            </head>
</html>

 Output


Body Tag: - Everything inside this element is shown inside the main browser window.  <body> is opening body tag and </body> is closing tag.

<html>
            <head>
                        <title> Hello </title>
            </head>
        <body>
                        <h1> Body of Page </h1>
        </body>
</html>


 Output

How to Create a Web Page
1. Open Notepad or any text editor
2. Write HTML Code

3. Save with .html extension i.e. hello.html

4. Done
(Click image for large view)

Click Below for Video Tutorial



Like it ? Share it.

Friday, July 24, 2015

Introduction to Code Blocks

Code Blocks is a free C, C++ and Fortran IDE built to meet the most demanding needs of its users. It is designed to be very extensible and fully configurable.

Finally, an IDE with all the features you need, having a consistent look, feel and operation across platforms.

Built around a plugin framework, Code::Blocks can be extended with plugins. Any kind of functionality can be added by installing/coding a plugin. For instance, compiling and debugging functionality is already provided by plugins!

1. Right click on Code Blocks icon and Open

 (Click image for large view)



2. This is Code Block Screen


3. Now we are going to create a new project for c programming so we could program our codes. Click on Create a New Project  


4. Select Console Application and Click Go


5. Click Next


6. Select C because we are going to study about C Programming language. Then click Next


7. Write your project title and click Next


8. Click Finish


9. Click on Plus ( + ) sign beside the source.


10. Double click on main.c file


11. Now you will see very basic program Hello World.



12. We will use only this button to compile our program/Run Program or you can press F9 from the keyboard.
(Click image for large view)
Video Tutorial 



Like it ? Share it.

Sunday, July 12, 2015

Conversion and Associativity

Mixed Mode Operation and Automatic (Implicit) Conversion– When operands of different data types are used in an arithmetic expression, one of the operand data type will be converted to the type of other operand. This conversion is taking place automatically during program execution and is referred to automatic type conversion or implicit conversion.
            The order of conversion is as follows:
char → int → long int → float → double
                   (Low ranking)                                                      (High Ranking)
Ex:
int m = 15;
float x = 3.1, y;
y = m*x;
                              │   ↓
                              ↓    Its type float is high rank.
                         Its type int is converted to float.

The result obtained by mixing float and int in the above expression is float, which is assigned to y.

Cast or Explicit Conversion – Cast operation is used to overcome automatic conversion. The variable declared in specific data type can be converted into the required type as shown below:
                       
                                    (type) expression
                                                Or
                                    (type) (expression)


Ex:
                        int m = 5;
                        float y;
y = (float) m/2;

In the above expression, the int variable m is converted into float to get the result 2.5; otherwise the result will be 2.


Operator Precedence and Associativity – The compute scans an expression which contains the C operators from left to right and performs only one operation at a time. The expression will be scanned many times to produce the result.
The order in which various operations are performed is known as hierarchy of operations or operation precedence.
            Some of the operators of the same level of precedence are evaluated from left to right or right to left. This is referred to associativity.
Ex:
                        S = s + x;
Associativity for the operator (+) is from left to right

                        S+= x;
Associativity for the operator (+=) is from right to left

Note – The operators in higher level will be executed first. When operators have the same level, the one at the left side will be executed first.

Precedence order
Operator
Associativity
1
( )     [ ]     →
Left to right
2
++   --   - (unary)   !   ~   *   &   sizeof
Right to left
3
  *     /      %
Left to right
4
+    -
Left to right
5
<<       >>
Left to right
6
 <        <=       >       >=
Left to right
7
==        !=
Left to right
8
  & (bitwise AND)
Left to right
9
  ^ (bitwise XOR)
Left to right
10
  | (bitwise OR)
Left to right
11
 && (logical AND)
Left to right
12
 | | (logical OR)
Left to right
13
 ? : (conditional)
Right to right
14
 =       +=     - =      *=      /=      %=
          
(assignment operators)
Right to left
15
  ,   (comma Operator)
Left to right


Structure of a C Program – C language does not actually follow any specific method of writing a program. It is a case sensitive language. All the statements must be written in lower case letters (small letters). The structure of a C program is as follows:-

<Header file>
<Global declaration of variable>
main ( )
{
                                    <local declaration of variables>
                                    ---------------------------------
                                    <statements>
                                    --------------------------------
}
                        <sub-programs- function blocks>

Note –
(i)                 The header files or preprocessor directives give instructions to the complier to include complier option (#include), macro substitution (#define) to substitute a constant for an identifier and conditional (#ifdef) directives.

(ii)               The main statement block, function block and other blocks used in a C program are enclosed in braces { }.

(iii)             Variable declared outside main ( ) are called global variables and they can be used in the main program block and sub program block.

(iv)             Variables declared inside main ( ) are called local variables, and they are used only in block in which they are declared. Sub program/function can also have local variables.

(v)               Any C program has coding in the form of letters and symbols. Normally documentation to the program is made by adding remarks or comment lines enclosed in /* and */ whenever necessary.







Like it ? Share it.

Friday, July 10, 2015

Operators and Expressions


Operators and Expression – An expression consists of variables and constants separated by operators. C language uses many type of operators as listed below:-
1.      Arithmetic Operators
2.      Relational Operators
3.      Logical Operators
4.      Increment and Decrement Operators
5.      Assignment Operators
6.      Conditional Operators
7.      Bitwise Operators

Arithmetic Operators - The basic arithmetic operators in C are the same as in most other computer languages, and correspond to our usual mathematical/algebraic symbolism. The following arithmetic operators are present in C:

Operators
Meaning
Example
Result
+
Addition
4+2
6
-
Subtraction
4-2
2
*
Multiplication
4*2
8
/
Division
4/2
2
%
Modulus operator to get remainder in integer division
5%2
1

Some of the examples of algebraic expressions and their C notation are given below:

Expression
C notation
b*g / b
(b*g) / b
a^3+cd
(a*a*a)+cd

Parentheses can be used in C expression in the same manner as algebraic expression For example,
a * (b + c).


The operands in arithmetic expressions can be of integer, float, double type. In order to effectively develop C programs, it will be necessary for you to understand the rules that are used for implicit conversation of floating point and integer values in C.
They are mentioned below:
         An arithmetic operator between an integer and integer always yields an integer result.
         Operator between float and float yields a float result.
         Operator between integer and float yields a float result.
         If the data type is double instead of float, then we get a result of double data type.
For example:
Operation
Result
5/3
               1
5.0/3
1.3
5/3.0
1.3
5.0/3.0
1.3

The rules of arithmetic precedence are as follows:

1.      Parentheses are at the “highest level of precedence”. In case of nested parenthesis, the innermost parentheses are evaluated first.
For example:
( ((3+4)*5)/6 )
The order of evaluation is given below.
( ( (3+4) * 5) / 6 )
                    ↓     ↓       ↓
                    1     2       3

2.      Multiplication, Division and Modulus operators are evaluated next. If an expression contains several multiplication, division and modulus operators, evaluation proceeds from left to right. These three are at the same level of precedence.
For example:
5*5+6*7
The order of evaluation is given below.
5*5+6*7
              ↓  ↓   ↓
              1  3   2

3.      Addition, subtraction are evaluated last. If an expression contains several addition and subtraction operators, evaluation proceeds from left to right. Or the associativity is from left to right.
For example:
8/5-6+5/2
The order of evaluation is given below.
8/5-6+5/2
 ↓  ↓  ↓  ↓
 1  3  4  2

Library Function (Intrinsic Functions or Math Functions) – To perform standard mathematical operations such as square root, absolute value and so on, built-in programs called library functions are available with the compiler. These functions can be used in an expression by mentioning their names with required number of arguments in parenthesis. Following are the commonly used mathematical library functions:-
(Click image for large view)

Note – The argument x used in this function is declared float or double and the complier directive #include<math.h>is used to include any of these functions in a C program.

Unary Plus ( + ) or Unary Minus ( – ) operations – When only one operand is used with + or – operators, the operation is called unary plus or unary minus, which does not actually refer to addition or subtraction. 
  
Relational Operators– Relational operators are used to compare the value of operands (expressions) to produce a logical value. A logical value is either true or false. Following are the relational operators used in C language:-

Operators
Meaning
Example
Result
< 
Less than
5>2
False
> 
Greater than
5>2
True
<=
Less than or equal to
5<=2
False
>=
Greater than or equal to
5>=2
True
==
Equal to
5==2
False
!=
Not equal to
5!=2
True

Note – In C language the logical value true is represented by integer 1 and false by 0 (zero).


Logical Operators – Logical operators are used to connect more relational operations to form a complex expression called logical expression. A value obtained by evaluating a logical expression is always logical, i.e. either true or false. Following are the logical operators in C:-

Operator
Meaning
Example
Result
&&
Logical AND
(5<2)&&(5>3)
False
||
Logical OR
(5<2)||(5>3)
True
!
Logical NOT
!(5<2)
True

Note – Logical not ( ! ) is an unary operator which requires only one operand. It is also referred as invertor which converts the value of the operand from true to false and vice versa.

The following truth tables to understand the logical values obtained using the logical operators:-
&&
Operand 1
Operand 2
Result
True
True
True
True
False
False
False
True
False
False
False
False

||
Operand 1
Operand 2
Result
True
True
True
True
False
True
False
True
True
False
False
False

!
Operand
Result
False
True
True
False


Increment ( ++) and Decrement ( -- ) Operators - The increment operator increments the variable by one and decrement operator decrements the variable by one. These operators can be written in two forms i.e. before a variable or after a variable. If an increment / decrement operator is written before a variable, it is referred to as pre-increment / pre-decrement operators and if it is written after a variable, it is referred to as post-increment / post-decrement operator.
For example:
a++ or ++a is equivalent to a = a+1 and
a-- or - -a is equivalent to a = a -1

The importance of pre and post operator occurs while they are used in the expressions. Pre-incrementing (Pre-decrementing) a variable causes the variable to be incremented (decremented) by 1, then the new value of the variable is used in the expression in which it appears. Post-incrementing (post-decrementing) the variable causes the current value of the variable are used in the expression in which it appears, then the variable value is incremented (decrement) by 1.

The explanation is given in the table below:

Operators
Meaning
++a
Increment a by 1, then use the new value of a
a++
Use value of a, then increment a by 1
--b
Decrement b by 1, then use the new value of b
b--
Use the current value of b, then decrement by 1

The precedence of these operators is right to left. Let us consider the following examples:
int a = 2, b=3;
int c;
c = ++a – b- -;
printf (“a=%d, b=%d,c=%d\n”,a,b,c);
OUTPUT
a = 3, b = 2, c = 0.
Since the precedence of the operators is right to left, first b is evaluated, since it is a post decrement operator, current value of b will be used in the expression i.e. 3 and then b will be decremented by 1.Then, a pre-increment operator is used with a, so first a is incremented to 3. Therefore, the value of the expression is evaluated to 0.
Let us take another example,
int a = 1, b = 2, c = 3;
int k;
k = (a++)*(++b) + ++a - --c;
printf(“a=%d,b=%d, c=%d, k=%d”,a,b,c,k);
OUTPUT
a = 3, b = 3, c = 2, k = 6
The evaluation is explained below:
k = (a++) * (++b)+ ++a - --c
= (a++) * (3) + 2 - 2                step1
= (2) * (3) + 2 – 2                    step2
= 6                                           final result 

Assignment Operator (C Shorthand) – Assignment operators are used to perform arithmetic operations while assigning a value to a variable.

Operator
Example
Equivalent Expression (m=15)
Result
+=
m +=10
m = m+10
25
-=
m -=10
m = m-10
5
*=
m *=10
m = m*10
150
/=
m /=
m = m/10
1
%=
m %=10
m = m%10
5

Conditional Operator ( ? : ) or Ternary Operators  - C provides an called as the conditional operator (?:) which is closely related to the if/else structure. The conditional operator is C’s only ternary operator - it takes three operands. The operands together with the conditional operator form a conditional expression. The first operand is a condition, the second operand represents the value of the entire conditional expression it is the condition is true and the third operand is the value for the entire conditional expression if the condition is false.

The syntax is as follows:
(condition)? (expression1): (expression2);

If condition is true, expression1 is evaluated else expression2 is evaluated. Expression1/Expression2 can also be further conditional expression i.e. the case of nested if statement (will be discussed in the next unit).

Let us see the following examples:
(i) x= (y<20) ? 9: 10;
This means, if (y<20), then x=9 else x=10;

(ii) printf (“%s\n”, grade>=50? “Passed”: “failed”);
The above statement will print “passed” grade>=50 else it will print “failed”

(iii) (a>b) ? printf (“a is greater than b \n”): printf (“b is greater than a \n”);

If a is greater than b, then first printf statement is executed else second printf statement is executed. 

Bitwise Operators– Bitwise operators are used to perform operations at binary digit level. These operators are not commonly used and are used only in special applications where optimized use of storage is required.

Operator
Meaning
<< 
Shifts the bits to left
>> 
Shifts the bits to right
~
Bitwise inversion (one’s complement)
&
Bitwise logical end
|
Bitwise logical or
^
Bitwise exclusive or

 Additional Operators – There two other operators that can be used in a C Program:-
1.      Sizeof operator
2.      Comma operator

Sizeof operator - C provides a compile-time unary operator called sizeof that can be used to compute the size of any object. The expressions such as:

sizeof object and sizeof(type name)

Result in an unsigned integer value equal to the size of the specified object or type in bytes. Actually the resultant integer is the number of bytes required to store an object of the type of its operand. An object can be a variable or array or structure. An array and structure are data structures provided in C, introduced in latter units. A type name can be the name of any basic type like int or double or a derived type like a structure or a pointer.
Example:
sizeof(char) = 1bytes
sizeof(int) = 2 bytes

Comma Operator - A comma operator is used to separate a pair of expressions. A pair of expressions separated by a comma is evaluated left to right, and the type and value of the result are the value of the type and value of the right operand. All side effects from the evaluation of the left operand are completed before beginning evaluation of the right operand. The left side of comma operator is always evaluated to void. This means that the expression on the right hand side becomes the value of the total comma-separated expression.
Example:
x = (y=2, y - 1);

First assigns y the value 2 and then x the value 1. Parenthesis is necessary since comma operator has lower precedence than assignment operator.

Generally, comma operator (,) is used in the for loop (will be introduced in the next unit)

For example:
for (i = 0,j = n;i<j; i++,j--)
{
printf (“A”);
}

In this example for is the looping construct. In this loop, i = 0 and j = n are separated by comma (,) and i++ and j—are separated by comma (,). The example will be clear to you once you have learnt for loop.

Essentially, the comma causes a sequence of operations to be performed. When it is used on the right hand side of the assignment statement, the value assigned is the value of the last expression in the comma-separated list.






Like it ? Share it.