Social Icons

Monday, December 24, 2012

For loop in C

for loop is also a kind of loop and used to execute a block of code for a specified number of times. It is the most widely used loop.


Syntax of 'for' loop


           for(initialization counter;loop condition;increment counter)
           {
                --------------------------------
                Some code to execute
                --------------------------------
           }


 Explanation of the syntax:


 There are 3 parts in the for loop written in a single line itself. They are:
  •  initialization counter - It is used to initialize the counter before execution of the loop starts.
  • loop condition - As the loop condition will be true, the execution of the loop will be continued. Its execution will be stopped when the loop condition is false.
  • increment counter - It is used to increase or decrease the value of counter each time after the end of each loop iteration. In other words, it will increase(or decrease) every time after the f block of code inside for loop will execute once.


 Now, lets see an example of for loop with a program.


 WAP to print numbers between 1 to 100 using for loop.


      #include<stdio.h>
      void main()
      {
           int i=1;
           for(i=1;i<100;i++)
           {
                 printf("%d\t",i);
           }
       }


   Explanation for the program:


           Here, we have initialized a variable i and set its value equal to 1. Now, it will come in for loop statement. Firstly, the initialization counter is there i.e, i=1. Then, it will check for the loop condition as i<100 i.e, currently 1<100 which is true. Then, it will execute the block of code written inside for loop i.e, printf statement. Now, it will print the value of i. Then, it will go to for loop statement again and will increase the value of i by 1 as i++ is there. So, now i=2. Again, it will check 2<=100 i.e, true. And value of i will be printed. Similarly, it will print from 1 to 100. \t is provided in the print statement as provide a tab space between each number.

Wednesday, December 19, 2012

do while loop in C

In the previous chapter, we read about while loop and its working. Herein this chapter, we shall read about the next loop in C i.e, do while loop. This loop is similar to while loop. But, the only difference is that do while loop at least execute the block of code once irrespective of the condition either true or false. In do while loop, firstly the block of code gets executed then the evaluation of condition takes place. If the condition is true then the block of code will again execute.


Syntax of do while Loop


            do
            {
                   --------------------------
                   Some Statements
                   --------------------------
            }
            while(condition);
             
Above is the syntax for do while loop. Now lets understand it with an example program.


 WAP to print 1 to 10 using 'do while' loop


          #include<stdio.h>
          void main()
          {
                 int no = 10, i=0;
                 do
                 {
                        i++;
                        printf("%d \n",i);
                 }
                 while(i < no);
          }


 Output :  1
                2
                3
                4
                5
                6
                7
                8
                9
                10


 Explanation for the above program:
 
                Here, we have taken two integer variables as no(//number) and i. Variable no is initialized to 10 and variable i is initialized to 0 as you can see in the program.  Then, it will come inside do and perform i++ i.e, value of i will be incremented by 1.  In the next line, with the printf statement, it will print the value of i i.e, 1 and goes to next line as \n is there. Now, it will come to while and check the condition if i<no. Till here, i = 1 and no = 10. So, it will check as while(1<10) means the condition is true and it will again go to the do statement and again execute the block of code inside do. So, value of i will be 2 now and it will be printed. Similarly, it will print upto 10 and then check for while(10 < 10) i.e false and come out of the loop.

Thursday, December 13, 2012

While Loop in C

While loop is one of the type of loops in C and used to repeat a block of code.

Syntax of while loop

          while (some condition)
          {
                 ---------------------
                 Some code to execute
                 ---------------------
                 increment/decrement
          }

     This loop will execute as long as the condition written in parentheses after while is correct. When the condition gets wrong, it will come out of the loop. If the condition is false in the very first then the block of code of while will not execute. Now, lets see an example of while loop using a program.

 WAP to print numbers between 1 to 100

             #include<stdio.h>
             void main()
             {
                   int  i=1;
                   while(i <= 100)
                   {
                          printf("%d \t", i);
                          i++;
                    }
               }

    Explanation:- Here, we have taken an integer variable 'i' initialized by 1. Now, it will come in while loop and will check its condition for the first time as i <= 100 means 1 <= 100. As the condition is true, it will go inside the loop and will print the value of i as 1. Again, there is an increment in i (i++). It will give one plus to the value of i. Now, i = 2. Again, it will check the condition of while as i <= 100. This time, it will check as 2 <= 100. Again, the condition is true and 2 will be printed. Similarly, it will be printed as  1 to 100. When value of i will be 101. It will check the condition as 101 <= 100. As the condition is false and it will come out of the loop.

Monday, December 10, 2012

Loops in C

Before discussing various loops in 'C', it is necessary to understand about loop, what exactly it is. We use loop when we have to repeat a block of code. For many times, it is required to execute the same code a number of times for some cases. Then we take the help of loop. 
                         There are three types of loop:- 
                          1.  while
                          2.  dowhile
                          3.   for

                 There are two keywords which are important in loop. So, before studying loops in deep, lets see these two keywords. They are:-
 1. break
 2. continue

 1. Break
               We use break to terminate the loop. In other words, we can say that it is useful to get exit from a loop under some circumstances. This will be more clear in using loops in next chapters.

2. Continue
                  Continue is a keyword that controls the flow of loops. Sippose we are executing a loop and hit a continue statement, the loop will stop its current iteration, update itself (in case of for loops) and begin to execute again from the top.

Sunday, December 9, 2012

If, Else, Else if Statements in C

If Statement
                     We use if statement when we have to enter in a section of code on the basis of some condition. For example, we use if statement to check if the username & password entered by user is correct then we allow him to do the particular task. Otherwise that area is restricted for him/her.
                          Whatever we write inside the if statement will execute only when the condition is true. If the condition is false, it will not execute. True returns a non-zero number(say 1) and false evaluates to zero.

If Syntax
                   The structure if if statement is as follows:-

          if (some condition)
          {
               ---------
               some code
               ---------
          }


Note:-  dashed lines show that some code will be there.

          Now, if the condition is true then only the code written inside of if will execute. Otherwise it will not execute.

Example:-   if ( 20 > 6)
                      {
                             printf("Condition is true");
                      }

 Now, here we see that 20 > 6 is true. So, it will go inside of if and will execute the printf statement and print the statement 'Condition is true'.

Else
          We use else when the condition in if evaluates to zero. But, its not necessary to put else everywhere you used if. It depends on your requirement. Suppose there is a condition. On the basis of that condition, you want to perform some operations. If the condition is true then some operations and if the condition is false then some different operations.

  Syntax for if else
              if (some condition)
              {                                                 // <- if condition is true, it will execute
                       ---------
                       Some code
                       ----------
               }
               else
               {                                               // <- if condition is false, it will execute.
                        ---------
                        some code
                       ----------
                }

      Example:-
                          if (20 < 6)
                          {
                                    printf("condition is true");
                           }
                           else
                           {
                                     printf("condition is false");
                            }

 Output:-  As here, the condition in if is not true, so else part will execute and it will print "condition is false" on the screen.

 Else If
       We use elseif when we have to execute some different instructions on the basis of some different conditions. Syntax for if, else, else if is as follows:-

      if ( condition 1)                      // It will check for this condition first
                                                     // If above condition is true, compiler will 

                                                      execute this block of code
      {

           -----------
           statement 1
           ------------
      }
      elseif ( condition 2)                   // if above condition is false, compiler will 

                                                            check this condition
     {                                                 // if this condition is true, compiler will 

                                                           execute this block of code.
          -------------
          statement 2
          ------------
     }
     elseif ( condition 3 )                   // if 2nd condition is false, compiler will 

                                                            check this condition.
     {                                                   // if this condition is true, compiler will execute this block of code.
           ------------
           statement 3
           ------------
     }
     else                                             // if none of condition is true, compiler will 

                                                            come here and execute it.
     {
           ------------
           statement 4
           ------------
     }

Example with a program using if, else, else if

WAP to enter percentage of marks and assign grade accordingly.

                 #include<stdio.h>
                 void main()
                 {
                       int no;
                       printf(" Enter your marks in percentage");
                       scanf("%d",&no);
                       if (no >=90)
                      {
                               printf("Your grade is A");
                      }
                      elseif (no >=75 && <90)
                      {
                               printf("Your grade is B");
                      }
                      elseif ("no >= 60 && < 75)
                      {
                               printf("Your grade is C");
                      }
                      else
                      {
                              printf("You didn't qualify");
                       }
                }

        
    Another Example for if else - WAP to check a number is odd or even

              #include<stdio.h>
              void main()
              {
                    int no;
                    printf ("Enter a number");
                    scanf ("%d",&no);
                    if (no % 2 == 0)
                   {
                         printf("Number entered is even");
                   }
                   else
                   {
                         printf("Number entered is odd");
                   }
              }

Saturday, December 8, 2012

C Program to swap two integers

 To start with the program, first its good to understand about swapping. Its possible that many people may not aware of this term. If you know, its good. Swap means interchange. Swap two numbers means to interchange the values of two numbers from each other. Suppose, x=15 and y=20. Then after swapping it will be x=20 and y=15. We have to write the program for the same. So, here we go:

                #include<stdio.h>
                void main()
                {
                       int x, y, temp;
                       printf("Enter two numbers");
                       scanf("%d%d",&x,&y);
                       printf("Before swapping, x=%d and y = %d \n",x,y);
                       temp = x;
                       x = y;
                       y = temp;
                       printf("After swapping, x=%d and y = %d",x,y);
               }

Ouptut: Before swapping, x=15 and y=20    (15 and 20 are the examples.. lets say these values are entered by user)
                 After Swapping, x=20 and y=15

Explanation for the program
                  Here, x and y are the two variables between which swapping has to be done. But, if we do first x=y. It means that value of y will be stored to x. But, now we have to get value of x stored in y. But, now its not possible because original value of x is lost as it holds now value of y. So, here we have used a third variable called temp(or say temporary). In this variable, firstly we have stored the value of x so that original value of x is not lost and then this value is assigned to y. In this way, these numbers are swapped.
                  Now, lets say you do it(swapping) without using third variable('temp' here). Wondering how is it possible. No need to wonder more... Here, I see you, how to do it???

WAP to swap two numbers without using third variable
        #include<stdio.h>
        void main()
        {
            int x,y;
            printf("Enter the two numbers to swap:");
            scanf("%d%d",&x,&y);
            printf("Before Swapping: x=%d \n y=%d \n",x,y);
            x = x+y;
            y = x-y;
            x=x-y;
            printf("After Swapping: x=%d \n y=%d \n",x,y);
        }
 Output:- Before swapping: x=15
                                                        y=20
                   After swapping: x=20
                                                    y=15
Explanation for the program
              Suppose we have two variables as x=15 and y=20. Now, according to the program  x = x+y;   => x = 15+20   => x = 35  y = x-y;    => y = 35-20    => y=15  x = x-y;    => x = 35-15    => x=20So, finally we get x=20 and y=15 which are the swapped values....

Friday, December 7, 2012

C Program to add subtract multiply and divide two integers

Lets understand the logic first for the program and then write it. Its a good practice to think about the logic before to write the program. So, here we have to perform algebraic operations like addition, subtraction, multiplication and division. It is obvious that we need two integers between which you have to perform various operations. Suppose, say it as x and y. Now, we need four integers here as the result each for addition, subtraction, multiplication and division. So, now start with the program:

               #include<stdio.h>
               void main()
               {
                       int x,y;
                       int sum, sub, mul, div;
                       printf("Enter two integer numbers");
                       scanf("%d",&x,&y);
                       sum = x+y;
                       sub = x-y;
                       mul = x*y;
                       div = int(x/y);
                       printf("Sum of the numbers=%d \n",sum);
                       printf("Subtraction = %d \n",sub);
                      printf("Multiplication of the numbers = %d \n",mul);
                      printf("Division between two numbers = %d \n",div);
               }

Explanation for the above program
                For the explanation of program from starting, you need to go to previous program. Here, I am explaining the other parts which is not explained earlier. Lets understand the program through an example. Suppose, two numbers enterd by user are 5 and 2.
Now, x = 5 and y = 4.
sum = x+y;  => sum = 5+4 = 9 .
sub = x-y;    => sub = 5-4 = 1.
mul = x*y    => mul = 5*4 = 20.
div = x/y      => div = 5/4 = 1.25 But, we have used div = int(x/y). So, it will take the division result into integer i.e, it will display the result as div = 1 instead of div = 1.25
This process is called type casting. Remember that type casting always occurs in right side as in above example. You can't use it in left side.

Thursday, December 6, 2012

Basic Programs in C

Lets start with the first program in 'C' as to print "Hello World". Its the best example to initiate to write programs in 'C' language.
1. C Program to print Hello World

              #include<stdio.h>
              void main()
              {
                     printf("Hello World\n");
              }

Output:-   Hello World
Note:- If you are using Devcpp to compile C program then use int main()  instead of void main().

Now, lets study the complete program step by step.
#include<stdio.h>
                                  Here, we include a file named as stdio.h (Standard Input/Output Header file). With the help of this file, we can use some certain commands for input or output in the program. Input commands like reading from keyboard and output command like print things to the screen.

void main()
                             Here, void is the return type and every program in 'C' must have a main(). Program actually starts from here only.

{ }
      These are the beginning and closing curly brackets respectively to group all commands together. Here, they are used to mark the beginning and end of the main() function.

printf("Hello World\n");
                                                           printf is used to print the things on the screen. Here, it will print Hello World on the screen. \n is used to break the line. It represents a new line character. Everything written after \n will be printed in a new line. The last ;(semicolon) indicates the termination of the printf line.


2. WAP to take a number as input and print it.

            #include<stdio.h>
            void main()
            {
                    int  a;
                    printf("Enter a number");
                    scanf("%d",&a);
                    printf("Number you entered is %d",a);
             }

       Output:-  Enter a number
                       5
                       Number you entered is 5

      Explanation for the program

                For the starting lines of the program as #include<stdio.h>, main() etc, you can refer the above first example's explanation. Now, we start it after main().

     int  a;
      Here, int  refers to integer and 'a' is variable written after int. It means, 'a' is an integer variable.

     printf("Enter a number")
           Whatever you will write in printf, it will be printed he same. So, on the screen, it will be printed as "Enter a number".

     scanf("%d",&a);
           scanf is used to take inputs from the user. You can say that these values entered by user is stored in computer's memory. Here, %d is used for integer variable.
For character, we use:-  %c
For float, we use:-            %f
After this there is &a. It is the integer variable defined after main().

     printf("Number you entered is %d".a);
                Now, the value of integer variable 'a' is stored in computer's memory. But you have to see it also. For that its necessary to print the value of 'a' on the screen. And, it requires a printf command. So, we have used here printf.
 But, herein this printf, we have also a %d. Actually this is also for the variable a whose value is entered by the user. Note that, after this, there is no '&'. But in scanf, it is necessary to include it.

Tuesday, December 4, 2012

Operators in C

To understand the different operators in 'C' , first let us understand about operators.Operator:- An operator is a symbol that operates on a certain data type and produces the output as the result of  operation. For example:-
                       x = y + z.
                      In this case:  '+' is the operator and y,z are operands.Now, let us know the different operators in 'C'. There are three categories of operators in 'C'. They are:
1. Unary Operators
                      It is an operator which operates on one operand or say it operates on itself. For example: increment and decrement operators. Examples: ++   --    !    etc.
2. Binary Operators
                      These operators are operators which operate on two operands. For example:   x+y. Here, '+' operats on two operands.
3. Ternary Operator
                           An operator which operates on three operands.

                Operators can also be classified on the basis of type of operations performed by them. They are as follows:-

1. Arithmetic Operators
                 Arithmetic operators include the basic addition(+), Subtraction(-), Multiplication(*) and Division(/) operations. One more operator is there called modulus operator(%). Hope, everyone is aware of +,-,*,/ operations. Here, the only new term is modulus operator. Let us understand this operator.
                        Modulus operator gives the remainder left on division operation. It is noted that its symbol is % but its not the percentage. For example:-
        10%3 = 1
Here, we divided 10 by 3 i.e 10/3. In this case, there will be quotient 3 and the remainder 1. So, remainder 1 will be the result. Some more examples are here:
        20%4 = 0
        25%7 = 4
        27%8 = 3

2. Relational Operators
                  These operators compare operands and return 1 for true or 0 for false. Examples of relational operators are:-
                 <    Less than                 >    Greater than
                <=   Less than or equal to
                >=   Greater than or equal to
                ==   Equal to
                !=     Not equal to


3. Logical Operators
                    These operators are used to compare or evaluate logical and relational expressions. There are 3 logical operators in 'C' language. They are:-
        &&  (Logical and) - In this case, if both conditions are true then result will be true.
        ||      (Logical OR) - In this case, if any condition is true between the two, result will be true.
        !       (Logical Not) - It inverts the condition. Makes true to false and false to true.


4. Assignment Operator
                   An assignment operator (=) is used to assign a value to a variable. It may be a constant value or a value of a variable. For example:-
            x = 5;     // Here, value 5 is copied to x
            x = a;    // Here, value of a is copied to x.

               Other assignment operators are:
              +=
              -=
              *=
              /=
             %=
                        These can be understood as follows:- Suppose we write
              x+=5;
               It means as x = x+5;
              Similarly,
              x-=10;   // It means x=x-10;

Monday, December 3, 2012

Data Types in C


Data Types in C Picture
Here, we are going to discuss data types in 'C' programming language. To discuss about the various data types in 'C', first it is necessary to understand what exactly are data types.
Data Type:- It can be defined as an extensive system for declaring
                          variables of different types. These are used to store various
                          types of data that is processed by program. It determines
                          memory to be allocated to a variable.
                 'C' supports various data types such as integer, character, float, real, double etc. Data types are of two types namely primitive and non-primitive data type.
1. Primary or primitive data types
                  These are the predefined data types whose memory sizes are already fixed. For example: integer, character, float etc.

2. Secondary or Non-primitive Data Types
                 These are the user defined data types and its memory size depends on user. For example:- Array, Structure etc. We will discuss these data types in later chapters.

Size and Range of Data Types
                 Here we will see the various primary data types in 'C' with their size(number of bytes required to allocate a variable) and its range.

Actually, its no need to remember the range of these data types. You wonder how they came. Lets see how the range came for the various data types. You only need to remember the bytes required for each data type.
        Suppose, we take the example of integer. As, we see that the bytes required for a character is 2 bytes. And, we know that 1 byte = 8 bits. So, 2 bytes = 8x2 = 16 bits. Raise it in the power of 2. So,
(2)16 = 2 to the power of 16 = 65536.
But, integer can be positive and negative both. So, divide the result by 2 i.e, 65536/2 = 32768.
Hence, its range will be -32768 to 32767.
It is noted here that there will be a zero between the range that's why the maximum is 32767.

                Similarly, range for any data type can be find out. Hope, now its easier for you to calculate and no need to remember it further...

Saturday, December 1, 2012

Introduction to C Programming Language

Picture
                                    'C' is a computer programming language. It was developed by Dennis Ritchie at Bell Laboratories in 1972. Its principle and ideas were mostly taken from B, BCPL(Basic Combined Programming Language) and CPL(Combined Programming Language).
                    'C' programming language becomes so popular because it is simple, reliable and easy to use. To learn other high level programming languages like C++, Java etc, it is advisable that you should know at least the basics of 'C'. Then only you can learn those programming languages perfectly.


Constants, Variables and Keywords
Constant:- A constant can be defined as an entity that doesn't change.
Variable:-  A variable can be defined as an entity that may change.
Keywords:- Keywords can be defined as the words that is already defined to the 'C' compiler.
                          There are 32 keywords in 'C' language. These keywords can't be used as the variable names.

                         Now let us understand about constants and variables with an example. Suppose, we have a statement as
    a = 10;

Then the value of 'a' is changed to 20. So,
   a = 20;
 
Here, we can see that the value of 'a' can be changed as per the user. So, it is a variable. But, numbers like 10, 20 etc are fixed and they are called as constants.

Friday, November 30, 2012

Make Login form using PHP MySql

Create Login Page Using PHP MySql

For most of the websites, it is a common requirement to have registration for users and accordingly login for them. Only users who have login account for the website like username and password, they can access most of the sections of the website. While unauthorized users (who doesn't have account for the website) can't. Herein this tutorial, we will read how to make a login page for any website. To understand this tutorial completely, I assume that you have basic knowledge of PHP, MySql. Anyway, I will try to explain each and every line of code in the tutorial. So, here we go.

Let us make a rough idea what we have to do. There will be a username column and a password column and a Login Button in the webpage. User will enter his/her username and password there and will click on Login button. It will check from database either these details match or not. If matches it will give success message else failure. So, firstly we need a database in which there will be a table and two columns as 'username' and 'password'. We will store email in username and any string in password.

Open your mysql with localhost/phpmyadmin. You can create a database there directly using GUI or by commands also. I provide you the query to write there.

Step 1 – Create a Database

Run this query in mysql:

CREATE DATABASE tutorials

This query will create a database named 'tutorials' in your mysql database. Here, 'tutorials' is the database name. You can replace it with your own name whatever you want.

Step 2 – Create a table (having columns username and password) in the above database


Now, we have to create a table in the database 'tutorials'. Now, select the database 'tutorials' in your  localhost/phpmyadmin. There run this query:


create table user (username varchar(50), password varchar(50))

This query will create a table named 'user' in the database 'tutorials'. It will have two columns as 'username' and 'password'. Varchar above in the query is the data type for username and password both. Both of them have size of 50 characters max. We could take char as data type also but then it would allocate 50 bytes for each. While varchar is flexible.

Now as no data is there in our database so we have to insert some data into it. Lets insert some username and password values into table 'user'. Run this query:

INSERT INTO user (username,password) VALUES ('prem@prembaranwal.com', '123')

It will insert a row having username value as prem@prembaranwal.com and password as 123.

Lets insert one more value similarly. Run this query:

INSERT INTO user (username,password) VALUES ('talkmeonprem@gmail.com', 'prem')

Now enough for the database part. Lets move to the front-end PHP and HTML part.

Lets create a login page. There will be a two textboxes for username and password where user will enter its username and password values. Apart from this there will be a submit login button. On clicking this button it will validate username and password as it is correct or not and display a message 'success' if correct and 'failure' if wrong.

Create a file named login.php

Code for login.php
            
            <html>
            <head>
            <title>Login Page in PHP</title>
            </head>
            <body>
            <form name=”myForm” action=”loginconnect.php” method=”POST”>
            <table>
            <tr>
                   <td>Username: </td>
                   <td><input type=”text” name=”username” id=”username” value=””/></td>
            </tr>
            <tr>
                   <td>Password: </td>
                   <td><input type=”password” name=”pwd” id=”pwd” value=””/></td>
            </tr>
            <tr></tr>
            <tr>
                   <td><input type=”submit” name=”login” value=”Login”/></td>
            </tr>
            </table>
            </form>
            </body>
            </html>


It will create a login page having username, password fields and submit button.

Now, user will enter its details in the textboxes and click on Login button. After clicking we have to check either the username and password is correct for the user or not. After clicking on Login button it will go to loginconnect.php page as it is written in form action in the above code ( see in login.php)

Lets write the code for loginconnect.php

Code for loginconnect.php

            <?php

            $user = $_POST['username'];  // store username entered by user

            $pwd = $_POST['pwd'];         // store password entered by user

            $con = mysql_connect("localhost","root","");  //establish connection to mysql database

            mysql_select_db("tutorials", $con);  //selects database tutorials
            $result = mysql_query("SELECT * FROM user WHERE username = '$user' and password='$pwd'”); // Query to check username and password is correct or not.

            $count = mysql_num_rows($result);  // Return number of rows from the above query

            if($count > 0)  // If it equals to 1 means username and password is correct
            {
                        echo “Successfully logged in”;
            }
            else
            {
                        echo “Either username or password is incorrect”;
            }

The description for the above code is given there in the comment itself for each line of code. I think these descriptions are enough to understand. Now run the login page.

Ø  Open your browser and type localhost/login.php in the url.

Ø  It will give you the login page containing username and password fields and login button.

Ø  Enter the details which we saved in our database.

Ø  In username, enter prem@prembaranwal.com and in password enter 123 and click on login button. It will give you successfully logged in message. Try with some wrong data and it will give you error message.

So, with this making basic login page finishes. Now, lets make it more better. We haven't put any validation here in the login page. Suppose if user doesn't enter anything in username and password and directly click on login button. In that case we can validate the form and ask user to enter those fields. Lets put validation in the form. Some modification is required in login.php file only.

Code for login.php with validation

            <html>
            <head>
            <title>Login Page in PHP</title>
            <script language=”javascript” type=”text/javascript”>
            function validateForm()
            {
                        var a = document.forms[“myForm”][“username”].value;
                        var b = document.forms[“myForm”][“pwd”].value;
                        if(a == null || a == “”)
                        {
                                    alert(“Enter Username”);
                                    return false;
                        }
                        if(b == null || b == “”)
                        {
                                    alert(“Enter Password”);
                                    return false;
                        }
            }
            </script>
            </head>
            <body>
            <form name=”myForm” action=”loginconnect.php” method=”POST”>
            <table>
            <tr>
                   <td>Username: </td>
                   <td><input type=”text” name=”username” id=”username” value=””/></td>
            </tr>
            <tr>
                   <td>Password: </td>
                   <td><input type=”password” name=”pwd” id=”pwd” value=””/></td>
            </tr>
            <tr></tr>
            <tr>
                   <td><input type=”submit” name=”login” value=”Login” onclick=”return validateForm()”/></td>
            </tr>
            </table>
            </form>
            </body>
            </html>


The above code will validate if the user has not entered username or password field and clicks on Login button directly. This results in a complete working login form in PHP.

Vedic Maths

Vedic Mathematics

 In simple words, we can say that vedic mathematics is just a unique method to make all of mathematical calculations faster. This helps in solving mathematical problems easily and in effective time. For example : Suppose you go to market to purchase something like books, clothes etc. The shopkeeper gives you some discount (say 33.5%). In this case, you find difficulty in calculating the percentage discount amount and whatever the shopkeeper ask, you pay it to him. But if you know vedic maths, then it will be easier to calculate them. It is also beneficial in exams for students. Today, time matters the most in competitive exams. Most person know the method to solve the question. But, there comes a matter of time who can solve faster. With vedic mathematics, you will be able to make calculations much faster without the need of calculator and the result will be solving problems in  lesser time as compared to others. Here, some of its important parts are covered. 

Vedic Maths Tutorials

1. Multiplication
             Multiplication is the part of algebraic maths where users find most difficulty to calculate it. But, it becomes very easier if you do it from vedic mathematics. Lets do it with vedic maths. You will surely enjoy it.

  i) Multiplication between 1 digit numbers
       Lets do multiplication between two 1-digit numbers. Suppose we have to multiply 9x6.
         Now 9 is 1 below to 10 and 6 is 4 below to 10. Write it like this,
          9        1
               X
          6        4 
          5        4   is the answer

Lets see how it came. For the left hand side digit(5), subtract the numbers diagonally from any side i.e 9 - 4 = 6 - 1 = 5. For the right hand sided digit, multiply the right hand sided numbers i.e 1x4 = 4. Now combine these, 54 will be the answer.

  ii) Multiplication of numbers near 100
           Now, lets do multiplication of two digit numbers close to 100. Suppose you have to multiply the numbers as 86x97. Again 86 is 14 below 100 and 97 is 3 below 100. Write it like this,
          97      3
               X
          86      14
          83      42  is the answer.

          Lets see how it came. For getting the left hand side number(83), subtract the numbers diagonally i.e 97 - 14 = 86 - 3 = 83. For the left hand sided number(14), multiply the last right hand side numbers i.e 3x14 = 42. Combine these, 8342 will be the answer.

  iii) Multiply numbers just above 100.
          Now see for multiplication between 3-digit numbers just over 100. Suppose you have to multiply 106x104. Lets do it with trick of vedic maths.
          106x104 = 11024.

          Lets see how it happened easily. Actually the answer is in two parts 110 and 24. First part 110 comes from (106+4) or (104+6). Second part 24 comes from multiplication between unit's place dit numbers i.e 6x4 = 24. So, 11024 is the answer.

You have seen how it is easy to do the multiplication with vedic mathematics. No need to use calculator or pick copy pen for it. Now, you can do it in your mind itself. So, just do some more practices. More you will practice, more you will remember these tricks.

2. Square of a number
    In this tutorial we will learn how to calculate square of a number very easily with vedic maths. Just in mind, you can do it.   
   i) Square of a two digit number ending with 5
         Suppose we have a number as 75. We have to find out the square of this number. For this, we have to use copy pen for it and multiply 75x75. It will take too longer. But from now, you will be able to do it in your mind. No need to use copy pen. Lets see :        75x75 = 5625 is the answer.

             Now lets see how it came very easily. Actually the answer is in two parts(56 & 25). If you have to square any number ending with 5 then write 25 in last. Its the right part of the answer. For the left part(56), just increment the ten's place digit by 1 and multiply with it i.e 7x(7+1) = 7x8 = 56. Combine these results 5625 is the answer. Similarly,85x85 = 7225  and rest you can try yourself.

   ii) Square of any two digit number
       Herein this method, we will learn to calculate square of any two digit number. At the first time, it is possible that you feel it something typical. But after practicing it, you will find it too easier and also it will save your much time. So, lets start : Suppose we have to square the number of 32.
     Square of 32  = 32x32 = 1024. is the answer.

   Lets see how the result came. Here start with the unit's place digit i.e 2. Square it. It will give you 4 (2x2). This the     unit's place digit of the answer. Now proceed, multiply the unit's place digit(2) and ten's place digit(3) and multiply   the result by 2(here, 2 is not the unit's place digit... It is always fix to multiply by 2) i.e(3x2x2) and the result will give 12. Write its unit's place digit before 4(calculate above as 2x2) and keep in mind the carry of 12 i.e 1. Now, we get the last two digit of the answer i.e, 24. Again proceed for the complete answer, Now, square the ten's place digit i.e 3x3 = 9. And we had a carry of 1 earlier. So, add this to 9. It will give 10. Write 10 before 24. Combining all these, 1024 will be the answer.

Note:- More vedic mathematics tutorials will be provided here very soon...Hope, you enjoyed it...

Total Pageviews