Monday, 24 November 2014

Statements In C

 Statements

 The statements of a C program control the flow of program execution.In C language several kinds of statements are available. They are

  1. if statement 
  2. switch statement
  3. goto statement
  4. for statement 
  5. while statement
  6. do-while statement
  7. break statement 
  8. continue statement 
  9. expression statement
  10. compound statement 
  11. return statement 
  12. null statement

if statements


If statement is a conditional branching statement. In conditional branching statement a condition is evaluated, if it is evaluate true a group of statement is executed. The simple format of an if statement is as follows:

if (expression) 
        statement;

 If the expression is evaluated and found to be true, the single statement following the "if" is executed. If false, the following statement is skipped. Here a compound statement composed of several statements bounded by braces can replace the single statement.

Here's an example program using simple if statement:

if else statement:


                    This feature permits the programmer to write a single comparison, and then execute one of the two statements depending upon whether the test expression is true or false. The general form of the if-else statement is

if(expression)
          statement1
else
          statement2

                    Here also expression in parentheses must evaluate to (a boolean) true or false. Typically you're testing something to see if it's true, and then running a code block(one or more statements) if it is true, and another block of code if it isn't. The statement1 or statement2 can be either simple or compound statement.

The following program demonstrates a legal if else statement:

      This brings up the other if-else construct, the  if, else if, else. This construct is useful where two or more alternatives are available for selection.

The syntax is
if(condition)
          statement 1;
else if (condition)
          statement 2;
          .....................
          .....................
else if(condition)
         statement n-1;
else
          statemens n ;

                The various conditions are evaluated one by one starting from top to bottom, on reaching a condition evaluating to true the statement group associated with it are executed and skip other statements. If none of expression is evaluate to true, then the statement or group of statement associated with the final else is executed.

The following program demonstrates a legal if-elseif-else statement:

  c switch statement

    Switch statements simulate the use of multiple if statement.The switch statement is probably the single most syntactically awkward and error-prone feature of the C language. Syntax of c switch statement is

switch(expression)
          {
          case constant1:
                       statements 1;
           break;
           case constant2:
                       statements 2;
           break;
           …………………..
          default:
                       statements n;
           break;
          }

                  When the switch statement is executed, the expression in the switch statement is evaluated and the control is transferred directly to the group of statements whose case label value matches the value of the expression. Each group of statement ends with a break statement. The execution of break statement causes immediate exit from the switch statement. If break statement is not present, then the execution will falls trough all the statement in the selected case.  If none of the case-label value matches the value of expression, then none of the group within the switch statement will be selected and the control is transferred directly to the statement that follows the switch statement c.

                  The expression that forms the argument of switch is evaluated to either char or integer. Similarly the constant expression follows the keyword case should be a value int or char. That is, names of variable can also be used. Switch can test for only equality.

                   Take a look at the following if-else code, and notice how confusing it can be to have nested if tests, even just a few levels deep:

int number = 10;
if(number == 1)
         {
         printf("Given number is 1\n");
         }
else if((number == 2)
        {
        printf("Given number is 2\n");
        }
else if((number ==3)
        {
        printf("Given number is 3\n");
        }
else if((number ==4)
        {
        printf("Given number is 4\n");
        }
else if((number ==5)
       {
        printf("Given number is 5\n");
        }
else
        {
        if(number<0)
                   printf("Given number is negative\n");
        else
                   printf("Given number is greater than 5\n");
         }
Now let's see the same functionality represented in a switch construct:
                 It’s illegal to have more than one case label using the same value. For example, the following block of code won't compile because it uses two cases with the same.
int temp = 100;
switch(temp)
         {
         case 10 : printf("10");
         break;
         case 10 : printf("10"); // won't compile!
         break;
         case 100 :printf("1000");
         break;
         default : printf("default");
         break;
         }
Break and Fall-Through in switch Blocks:
                 When case constants are evaluated from the top to down, and the first case constant that matches the switch's expression is the execution entry point. In other words, once a case constant is matched, C will execute the associated code block, and all subsequent code blocks .
Example:















































Keywords ,Variables , Expression in C

Keywords

 Keywords are standard identifiers that have standard predefined meaning in C. Keywords are all lowercase, since uppercase and lowercase characters are not equivalent it's possible to utilize an uppercase keyword as an identifier but it's not a good programming practice.

Points to remember

1. Keywords can be used only for their intended purpose.

2. Keywords can't be used as programmer defined identifier.

3. The keywords can't be used as names for variables.

The standard keywords are given below:

The standard keywords are given below:








Variables

 Variables are means for location in memory used by a program to store data. The size of that block depends upon the range over which the variable is allowed to vary.
For example, on personal computer the size of an integer variable is two bytes, and that of a long integer is four bytes.
A variable region is temporarily remember a number or string value, such as covered by the program. To identify the variables, you have a name unique to every single variable. This is called a variable name. Before using a variable, use variables to what is called a variable declaration that you have to reveal the names and data types that can be stored in the variable variable.

The format for declaring a variable in C.
[Storage-class] type data variable name [= initial value];

Storage class and the initial value can be omitted.

The same data type and storage class variable can be declared, separated by commas.
[Storage-class] type data variable name [= initial value] variable [= initial value] variable [= initial value];
              In C the size of a variable type such as an integer need not be the same on all types of machines. When we declare a variable we inform the compiler of two things, the name of the variable and the type of the variable. For example, we declare a variable of type character with the name i by writing:
char i;
             On seeing the "char" part of this statement the compiler sets aside one bytes of memory to hold the value of the character. It also sets up a symbol table. In that table it adds the symbol i and the relative address in memory where those one byte was set aside. Thus, later if we write: i = 'x'; we expect that,at run time when this statement is executed, the value 'x' will be placed in that memory location reserved for the storage of the value of i.
Following are the rules for naming the variables:
  1. All variables must be declared before they can appear in executable statement.
  2.  A declaration consists of a data type followed by one or more variable names separated by commas.
     Example: int a,b,c;
  3. Variables can be distributed among declarations in any fashion. The above declaration can be written as
    int a;
    int b,c;
  4. Integer type variables can be declared to be short integer for smaller integer quantities or long integer for larger integer quantities.
    Example:
    short int a,b,c;
    long int a,b,c;
  5. An integer variable can also be declared to be un signed by writing unsigned int.
    Example: unsigned int;
Example:

Expressions

              An expression is a sequence of operators and operands that specifies computation of a value. An expression may consist of single entity or some combination of such entities interconnected by one or more operators. All expression represents a logical connection that's either true or false. Thus logical type expression actually represents numerical quantities.
              In C every expression evaluates to a value i.e., every expression results in some value of a certain type that can be assigned to a variable. Some examples of expressions are shown in the table given below.
A+b
3.14*r*r
a*a+2*a*b+b*b
Example:














Thursday, 26 April 2012


Mouseover Hyperlinks Tips


If you want to make your site fancy, these tips are for you!
The tips and tricks in this post allow two different types of mouseover links.

The first is one that will act as if visitors have clicked the link when they have simply put their mouse on top of it.
For example, look at the following link:
Look at this site!
It was made with this code:
<a href=" "onmouseover="parent.location='http://google.com'"> Look
at this site!
</a>

Copy and paste the code into your HTML code and the change the text in italics and you are done!

The second mouseover link tip is one that will show a pop-up window when a visitor puts his or her mouse on the link.
Look at this link:
I like web pages
It was made with slightly different code than the previous tip. Look at the HTML:
<a href="" onMouseover="alert('That answer is correct')">I like web pages</a>
Copy and paste that code into your web page's HTML code and remember to change the text in italics.

The Nice Mailto Trick


If you ever want someone to e-mail you, than mailto is your answer!
When you insert this command into your html code, a link will be created.
Whoever clicks on this link will have their default mail client pop up!
Look at this code:
<A HREF="mailto:?">Send me an email</A>
This is how it looks to the viewer:
Send me an email
We can also before the question mark, type in the address which the viewer is to send the e-mail to, and look at what happens.
<A HREF="mailto:Vishrulzz@ymail.com?">Send me an email</A>
Send me an e-mail
We can also add something to the subject line, too.
Look at what happens. We have added subject=This text is on the subject line&
<A HREF="mailto:
Vishrulzz@ymail.com?subject=This text is on the subject line&">Send me an email</A>
Send me an e-mail
OK, finally, we can even add text in the actual e-mail!
Look at what happens as we add body=This text is in the e-mail
<A HREF="mailto: Vishrulzz@ymail.com ?subject=This text is on the subject line&body=This text is in the e-mail">Send me an email</A>
Send me an e-mail 
Check It out...
Have fun..

Linking to Other Parts of the Same Webpage


Before you can link to a part of your webpage you need to mark that part of the web page.
You do this by inserting this into the webpage:
<A NAME="Anyname"> Bla, bla, bla </A>
This is how it looks to the viewer:
Bla, bla, bla
Then, you make the link. Here's the code:
<A HREF="#Anyname">Go back to  
 Bla, bla, bla  </A>
Here's the output: (See what happens)
Go back to bla, bla, bla
Oooh.

Having Columns Like in a Newspaper


This is column 1 and this is column 1 and this is still column 1This is column 2 and this is column 2 and this is still column 2This is column 3 and this is column 3 and this is still column 3

The source code for the colums was this:
<TABLE BORDER="0">
 <TR>
 <TD WIDTH="30%" VALIGN="TOP">
  This is column 1 and this is column 1 and this is still column 1<BR>
 </TD>
 <TD WIDTH="5%"></TD>
 <TD WIDTH="30%" VALIGN="TOP">
  This is column 2 and this is column 2 and this is still column 2<BR>
 </TD>
 <TD WIDTH="5%"></TD>
 <TD WIDTH="30%" VALIGN="TOP">
  This is column 3 and this is column 3 and this is still column 3<BR>
 </TD>
 </TR>
</TABLE>

 

When inserting the code, make sure you put it into very few lines.
Change all the little percentages to adjust the coloums, and also make sure you change the text. 

Have Text Highlighted


This is the code for normal text: 
HTML TEXT 
It will create this: 
HTML TEXT 
To have HTML highlighted, change the code to this: 
<span style="background-color: #FFFF00">HTML</span> TEXT 
It will create this: 
HTML TEXT 
This html tip will make your page even fancier. 

Justify Text


Look at the code for justifying text:
<p align="justify">bla bla bla bla blablabla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
</p>

It creates this justified text: 
bla bla bla bla bla bla blablabla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 

(Unjustified text:
bla bla bla bla bla bla bla bla bla bla bla blablabla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
See the difference?)

That is how you justify text. 

Blockquote Tips


Blockquote makes a small text box that is indented, as in a quote.
This text is a little to the right because of the blockquote tag. To learn how to make a blockquote like this one, continue reading HTML Tips and Tricks.

To make a blockquote, simply copy and paste the following HTML code:
<blockquote>Text Text Text</blockquote>
Finally, change the "Text Text Text" message to suit your needs.
Result:
Text Text Text

Pre-Formatted Text


These tips and tricks will allow you to have greater control over text.

To preformat text, you will need to look at the following html:

<pre>
      This text is
           preformatted
</pre>


It will display the following:


      This text is
           preformatted

If you simply were to remove the <pre> tag, like this:
      This text is
           preformatted

Then this text would be displayed:

This text is
preformatted


Here is another example of the uses of preformatting text.

Text Formatting tips

Plain old text needs a few html tips.
That is why I will show some html which will improve plain old text.

Html Tip 1: To insert plain old text simply insert any text between the <body> and </body> tags.
Example:
This is html text
Code:
This is html text

Html Tip 2: To make text bold, underlined, or be in italics, add the corresponding tag on the sides of the text.
To make text bold, insert the <b> and </b> tags on the sides of the text.
To make text in italics, insert the <i> and </i> tags on the sides of the text.
To make underlined, insert the <u> and </u> tags on the sides of text.
And, finally, here is a bonus tip:
You can put a line through text by placing the and tags on the sides of the text.
Example:
This is html text in italics.
Code:
<i>This is html text in italics</i>

Html Tip 3: To change the font itself, font size and colors, look at this:
To change the color:
add the <FONT COLOR="color name in english"> and </font color> to the sides of the text.
To change the font size:
add the <font size=number from 1-7> and </font> to the sides of the text.
To change the font:
add the <font face="font name"> and </font> to the sides of the text.
In addition, you can put commas between different fonts like this:
<font face="artistik,arial">This can be in different fonts.</font>
This html code creates text which will be in the artistik font. However, if the computer does not have an artistik font, then the text will be written in arial.
Here is what the html does on your computer:
This can be in different fonts
Here is another example of changing the font size, text or colors:
<font color="red">This is html text in red</font>
And that creates this:
This is html text in red
And finally, another example for people who really like changing fonts:

<b>
<font color="red" font size=5 font face="artistik,times,arial">Fancy html text</font>
</b>

Bullets and Lists

These html tips and tricks will help you put bullets and lists on your blog.

Let's start with simple bullets.

For this html tip, look at this bullet:

  • This is next to a bullet

  • It was made with this simple HTML code:
    <li>This is next to a bullet</li>
    Insert the above code to your web page,
    and then change the message to suit you needs.

    ...And now let's end with more advanced tips, concerning lists.


    To make numbered bullets,

    1. Like these

    2. ones
    use this HTML code instead:
    <ol><li>Like these</li>
    <li>ones</li></ol>

    Note that the <ol> is only put at the extremes of the list.



    There are also some tips and tricks that will allow different types of bullets:

    1. Lower Case Roman Numerals
    HTML Code:
    <ol type="i"><li>Lower Case Roman Numerals</li></ol>

    1. Upper Case Roman Numerals
    HTML Code:
    <ol type="I"><li>Upper Case Roman Numerals</li></ol>

    1. Lower Case Alphabet
    HTML Code:
    <ol type="a"><li>Lower Case Alphabet</li></ol>

    1. Upper Case Alphabet
    HTML Code:
    <ol type="A"><li>Upper Case Alphabet</li></ol>


    Finally, text inside these bullets can be formatted with this tip.

    Links and Images Basics


    These tips and tricks will teach you how to put a link or an image into an html page.

    To put a link, use the following code:
    <a href="http://google.com">Google</a>
    The result is as follows:
    Google
    Make sure you change "http://google.com" to the address of the site that you want to link to and that you change "Google" to the text that you want users to see.

    To put an image into your web page, use the following code:
    <img src="http://www.google.com/intl/en/images/logo.gif">
    The result of that code is as follows:

    Make sure that you change "http://www.google.com/intl/en/images/logo.gif" to the address of the image you want to display.

    So those are two basic html tips!


    Customize  Headings



    These html tips and tricks will show you different types of headings.


    Look at the following html code:
    <h2>Heading 2</h2>
    It creates this heading:

    Heading 2



    Now looking at this html code:
    <h3>Heading 3</h3>
    It now creates this slightly smaller heading:

    Heading 3



    The 2 and 3 in H2 and H3 can be changed to any number between 1 and 6 to make different sorts of headings.
    Here is an example of some code that uses headings:
    <h4>Heading 4</h4>
    Heading 4 is the fourth most important heading.
    <h5>Heading 5</h5>
    Heading 5 is the fifth most important heading.

    The code results in the following:

    Heading 4



    Heading 4 is the fourth most important heading.
    Heading 5


    Heading 5 is the fifth most important heading.

    New Line Tips

    Sometimes you want there to be a large number of empty lines.
    If you do, you will have to use <br>
    Simply insert <br> wherever you want there to be a new line.
    For example, if you want 5 lines to be skipped, use this html code:
    <br><br><br><br><br>
    It will create this:










    You can put the br tag nearly anywhere in your html document. Make sure that it is in the body, however.

    Create a Web Page by Simple HTML codes



    Build a Web Page



    This tip will tell you exactly how to code your own HTML website.

    First, remember that most tags must be eventually closed. The syntax would be: <tag> CONTENT </tag>.

    Open a text editor such as notepad, or the HTML editor for your hosting service.

    The first tag in your website should be <html>, which starts the HTML site.
    Immediately after this should come the <head> tag.

    So far, you should have the following:

    <html>
    <head>

    The next step is to enter the title of your website. This is what shows up in the title bar of the internet browser. Put the title between the <title> and </title>. Then, end the head with </head>. You will end up with:


    <html>
    <head>
    <title>TITLE</title>
    </head>

    Other data to put into the head includes metadata and stylesheet data.

    The next step is to add the body of your website. This is where all the important stuff goes. Start out the body with the <body> tag. In a basic website, all the real content goes in the body.

    The most basic way to write the body is to simply write a heading, then type.

    Within the body, start off by writing the first heading. This should be big, so the <h1> tag should do the trick. After that, simply write the text of the site. Remember the syntax for making links:

    <a href="http://www.linktarget.com">LINK</a>

    And for making images:

    <img src="http://imagesite.com/image.jpg"> .

    Remember, most HTML Tips can be simply inserted into the body and used immediately.

    Finish off the body with </body>, and the body is done.

    The code with the body included should look like:


    <html>
    <head>
    <title>TITLE</title>
    </head>
    <body>
    <h1>THE SITE</h1>
    blablabla
    <a href="http://www.linktarget.com">LINK</a>
    IMAGE:
    <img src="http://imagesite.com/image.jpg">
    </body>

    Remember, you still have 1 more tag to close: the <html> tag. Close it with </html>, and your website is complete. The final code:


    <html>
    <head>
    <title>TITLE</title>
    </head>
    <body>
    <h1>THE SITE</h1>
    blablabla
    <a href="http://www.linktarget.com">LINK</a>
    IMAGE:
    <img src="http://imagesite.com/image.jpg">
    </body>
    </html>

    If you want to see what that code looks like in a real web browser, go to this page, which uses the exact HTML code above:


    Your basic website is complete! For more advice on tables, frames, text formatting, Javascript, etc., look at the rest of the tips on this site. Almost all of them can simply be inserted in the body. Now you know how to make your website from HTML!

    Also, if you are using Blogger, you can go to the "template" section of the dashboard, and edit the template, which is raw HTML. Be careful not to change too much stuff. The beginning data is stylesheet data, so don't mess around unless you know what you're doing. However, you can find the sidebar, and mess around with that quite freely.

    You can always use a program like Frontpage or Dreamweaver, but raw coding is always the best way to make your website exactly like you want it!

    Saturday, 21 April 2012


    Life is a challenge –meet it 

    Life is a gift –accept it

    Life is a sorrow-overcome it 
    Life is a tragedy-face it
    Life is a adventure-dare it
    Life is a duty- perform it
    Life is a mystery-unfold it
    Life is a song –sing it
    Life is a opportunity-take it
    Life is a journey-complete it
    Life is a promise fulfill it 
    Life is a beauty-praise it 
    Life is a goal-achieve it
    Life is a puzzle-solve it    
    Life is love-love it    







    Life is the sum of experiences that we encounter as we go
    through life. Day to day struggles and triumphs are experienced by all of the world's creatures. As human beings, when we encounter a challenge, we have freedom to choose how to react. Every decision that we make leads us down a different road. We will never come to exactly the same crossroads. Every decision the we make has significance. The tiniest choice that we make reverberates throughout the entire universe.



    Thought  By :-
    Prashant Verma