Tuesday, 30 July 2013

Example of HTML PHP Comment

Type the following code in your text editor..

<HTML>
<HEAD>
<TITLE>Example of Comments</TITLE>
</HEAD>
<BODY>
<!-- html comment style -->

<?
// This is a single line PHP comment style.

# Shell type comment style.
/* This is a C style comment, we can use it for multiple lines 

this is suitable for multiple line comment */
?>

</BODY>
</HTML>


Now save this file as comment.php

Comment in PHP

Various types of syntax are used  to add comment in PHP.

Syntax 1

// this is single line comment in php code.

Syntax 2

# this is another style of comment in php code called shell-style.

Syntax 3


/* this is C-style comment in php code used for upto two lines */

Syntax 4

<!   example of html comment which is ignored by browser  >

Sunday, 28 July 2013

Print Quotient and Remainder in C++

// Write a C++ program that takes two values of x(dividend) and
// y(divisor) from user and prints quotient and remainder of x/y

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int x,y,q,r;
    cout<<"Enter dividend number x : ";
    cin>>x;
    cout<<"Enter divisor number y : ";
    cin>>y;

    cout<<"\n\n------------------------------------\n";
    cout<<" Quotient and Remainder of x/y \n";
    cout<<"------------------------------------\n";

    q = x / y ;
    r = x % y;
    cout<<"Quotient  = "<<q<<endl<<"Remainder = "<<r;
    getch();
}


Saturday, 27 July 2013

PHP Start and End tags

There are three basic types of PHP Start and End tags which is also called PHP Opening and Closing tags respectively.


Figure: PHP Starting and Ending Tags


Examples:

You can use any type of php tag in your script.

<?
echo "<P>Example of 1st type of PHP tag.</P>";
?>


<?php
echo "<P>Example of 2nd type of PHP tag.</P>";
?>


<script language="php">
echo "<P>Example of 3rd type of PHP tag.</P>";
</script>


Wednesday, 24 July 2013

Even Numbers in Descending Order

// Write a C++ program that prints odd numbers in
// descending order from a given range.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Even numbers in Descending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 != 0 )
    n--;
    for( i = n ; i >= 0 ; i = i-2 )
    cout<<"         "<<i<<endl;
    getch();
}

Sunday, 21 July 2013

Even Numbers in Ascending Order

// Write a C++ program that prints even numbers in
// ascending order up to given range.


#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number for ending range : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Even numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    for( i = 0 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

Odd Numbers in Ascending Order

// Write a C++ program that prints odd numbers in
// ascending order up to given number.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = 1 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

Wednesday, 17 July 2013

Odd numbers in descending order

// Write a C++ program that prints odd numbers in 
// descending order from a given input.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Descending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = n ; i >= 1 ; i = i-2 )
    cout<<"  "<<i<<endl;
    getch();
}


Monday, 15 July 2013

Temperature Conversion

Convert Fahrenheit to Celsius

C = 5/9(F - 32)

Convert Celsius to Fahrenheit


F = 9/5(C + 32)


Convert Celsius to Kelvin


K = C + 273.15

Convert Kelvin to Celsius

C = K - 273.15

If you are interested in C++ programming, please visit the following links.

Kelvin to Celsius Conversion

// Write a C++ program to convert temperature from
// Kelvin to Celsius.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float k,c;

    cout<<"\n------------------------------------\n";
    cout<<"  Kelvin to Celsius Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Kelvin : ";
    cin>>k;
    c = k - 273.15 ;
    cout<<"\n\n Temp in Kelvin = "<<c;
    getch();
}


Celsius to Kelvin Conversion

// Write a C++ program to convert temperature from
// Celsius to Kelvin.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float c,k;

    cout<<"\n------------------------------------\n";
    cout<<"  Celsius to Kelvin Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Celsius : ";
    cin>>c;
    k = c + 273.15 ;
    cout<<"\n\n Temp in Kelvin = "<<k;
    getch();
}

Sunday, 14 July 2013

Farenheit to Celsius conversion

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float f,c;

    cout<<"\n------------------------------------\n";
    cout<<"  Farenheit to Celsius Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Farenheit : ";
    cin>>f;
    c = (f-32)/1.8;
    cout<<"\n\n Temp in Celsius = "<<c;
    getch();
}

Celsius to Farenheit Conversion

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float c,f;

    cout<<"\n------------------------------------\n";
    cout<<"  Celsius to Farenheit Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Celsius : ";
    cin>>c;
    f=(9/5)*c+32;
    cout<<"\n\n Temp in Farenheit = "<<f;
    getch();
}

Saturday, 13 July 2013

if else statement syntax

C++ "if" statement contains following elements.
  • Test expression
  • if body

Figure: if statement

The operation of "if" statement is explained by using flow chart.

Figure: if statement flow chart

if statement syntax

C++ "if" statement contains following elements.
  • Test expression
  • if body

Figure: if statement

The operation of "if" statement is explained by using flow chart.

Figure: if statement flow chart

Friday, 12 July 2013

do while loop syntax

C++ "do while loop" contains following elements.
  • Test expression
  • Increment expression
  • Loop body
 
Figure: do while loop

The operation of "do while loop" is explained by using flow chart.

Figure: do while loop flow chart

while loop syntax

C++ "while loop" contains following elements.
  • Test expression
  • Increment expression
  • Loop body

Figure: while loop syntax

The operation of "while loop" is explained by using flow chart.

Figure: while loop flow chart

for loop syntax

C++ "for loop" contains following elements.
  • Initialization expression
  • Test expression
  • Increment expression
  • Loop body


Figure: for loop syntax

The operation of "for loop" is explained by using flow chart.

Figure: for loop flow chart

Wednesday, 10 July 2013

Print Table in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int x,y;
    cout<<"Enter any number to print that table : ";
    cin>>x;

    cout<<"\n------------------------------- \n";
    cout<<"   Multiplication Table \n";
    cout<<"------------------------------- \n";

    for( y = 1 ; y <= 10 ; y++ )
    cout<<"       "<<x<<" X "<<y<<" =  "<<x*y<<endl;
    getch();
}

Prime Numbers from 1 to 500 in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a,b,temp;
  
    cout<<"--------------------------------\n";      
    cout<<"  Prime Numbers from 1 to 500  \n";
    cout<<"--------------------------------\n\n";
  
    for(a = 2 ; a <= 500 ; a++)
    {
        temp=0;
        for(b = 2 ; b < a ; b++)
        {
            if(a % b == 0)  
            temp = 1;  
        }
        if(temp == 0)
        cout<<a<<" ,";
    }  
    getch();
}

Sum of Prime Numbers from 1 to 1000 in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a,b,temp;
    double sum = 0;
   
    cout<<"--------------------------------------\n";
    cout<<"  Sum of Prime Numbers from 1 to 1000  \n";
    cout<<"--------------------------------------\n\n";
   
    for(a = 2 ; a <= 1000 ; a++)
    {
        temp=0;
        for(b = 2 ; b < a ; b++)
        {
            if(a % b == 0)   
            temp = 1;   
        }
        if(temp == 0)
        sum = sum + a ;
    }
    cout<<sum;
    getch();
}

Sum of Prime Numbers from 1 to 500 in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a,b,temp;
    int sum = 0;
   
    cout<<"--------------------------------------\n";
    cout<<"  Sum of Prime Numbers from 1 to 500  \n";
    cout<<"--------------------------------------\n\n";
   
    for(a = 2 ; a <= 500 ; a++)
    {
        temp=0;
        for(b = 2 ; b < a ; b++)
        {
            if(a % b == 0)   
            temp = 1;   
        }
        if(temp == 0)
        sum = sum + a ;
    }
    cout<<sum;
    getch();
}

Tuesday, 9 July 2013

Even and Odd number test in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int x;
    cout<<"Enter any number : ";
    cin>>x;

    if ( x % 2 == 0 )
    cout<<endl<<x<<" is Even number"; //Remember 0 is an even number
    else
    cout<<endl<<x<<" is Odd number";
    getch();
}

Monday, 8 July 2013

IF Statement tutorial in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr() ;        //to clear output screen at the beginning
    int  i ;        //decleration   
    cout<<"Enter any number: ";
    cin>>i ;
   
    if( i > 50 )
    {
        cout<<"The number is greater than 50 ";
        cout<<endl;
    }
    getch();
}

Print Table in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int a,b;
    cout<<"\nEnter any number : ";
    cin>>a;
    cout<<"\n\n---------------------\n";
    cout<<" Print Table \n";
    cout<<"---------------------\n\n";
    for(b=1 ; b<=15 ; b++)
        cout<<a<<" * "<<b<<" = "<<a*b<<"\n";
    getche() ;
}

Counter in C++

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int a = 0;
    char quit;
    cout<<"\n\n--------------------------------\n";
    cout<<" Counter (Hit any key to count)\n";
    cout<<"--------------------------------\n\n";
    gotoxy(1,12);
    cout<<"--------------------------------\n";
    cout<<" Press \"q\" to quit ";
    while(quit != 'q' && quit != 'Q')
    {   
        gotoxy(16,8);
        cout<<a;
        a++;
        quit = getch();
    }   
}

C++ While Loop

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr() ;        //to clear output screen at the beginning
    int  i   ;        //decleration
    i = 1 ;        //initialization
    while( i < 5 )
    {
        cout<< i ;
        cout<<" The while loop" ;
        cout<<endl ;    
        i++ ;   
    }
    getch();
}

C++ For Loop

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr() ;        //to clear output screen at the beginning
    int  i   ;        //decleration
   
    for( i = 1 ; i < 5 ;  i++  )
    {
        cout<< i ;
        cout<<" The for loop" ;
        cout<<endl ;
    }
    getch();
}

Print Hello World in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    cout<<"Hello World";
    getch();
}

Find Square of a number in C++

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float n,a;
    cout<<"Enter any number : ";
    cin>>n;
    a = n*n;
    cout<<"Square of "<<n<<" is = "<<a;
    getch();
}

Print prime numbers from 1 to 1000 in C++

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int a,b,temp;
   
    cout<<"--------------------------------\n";       
    cout<<"  Prime Numbers from 1 to 1000  \n";
    cout<<"--------------------------------\n\n";
   
    for(a = 2 ; a <= 1000 ; a++)
    {
        temp=0;
        for(b = 2 ; b < a ; b++)
        {
            if(a % b == 0)   
            temp = 1;   
        }
        if(temp == 0)
        cout<<a<<" ,";
    }   
    getch();
}

Print Odd numbers from 1 to 500 in C++

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int a=1 , b=500; //you can extend this range i.e b=1000
    cout<<"\n\n---------------------\n";
    cout<<" Odd Numbers \n";
    cout<<"---------------------\n\n";
    while(a<=b)
    {   
        if(a%2!=0)     
            cout<<a<<" ,";
        a++;
    }   
getche() ;
}

Print Odd number in C++

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int a,b;
    cout<<"\nEnter starting range : ";
    cin>>a;
    cout<<"\nEnter ending range : ";
    cin>>b;
    cout<<"\n\n---------------------\n";
    cout<<" Odd Numbers \n";
    cout<<"---------------------\n\n";
    while(a<=b)
    {   
        if(a%2!=0)
            cout<<a<<" ,";
        a++;
    }   
getche() ;
}

Print even number in C++

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    int a,b;
    cout<<"\nEnter starting range : ";
    cin>>a;
    cout<<"\nEnter ending range : ";
    cin>>b;
    cout<<"\n\n---------------------\n";
    cout<<" Even Numbers \n";
    cout<<"---------------------\n\n";
    while(a<=b)
    {   
        if(a%2==0)
            cout<<a<<" ,";
        a++;
    }   
getche() ;
}

C++ Calculator

#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,z;
char oper;
clrscr();
cout<<"\nEnter First Number  A = ";
cin>>a;
cout<<"\nEnter Second Number B = ";
cin>>b;
cout<<"\nChose Your Operation";
cout<<"\n--------------------";
cout<<"\n1 - Addition";
cout<<"\n2 - Substraction";
cout<<"\n3 - Product";
cout<<"\n4 - Division";
cout<<"\n--------------------\n";
cin>>oper;
cout<<"\nResult:\n\n";
switch(oper)
{
case '1':
           z=a+b;
    cout<<"A + B = "<<z;
           break;
case '2':
    z=a-b;
           cout<<"A - B = "<<z;
           break;
case '3':
    z=a*b;
           cout<<"A * B = "<<z;
           break;
case '4':
    z=a/b;
           cout<<"A / B = "<<z;
           break;
default:
    cout<<"Invalid Choice";
}
getch();
}

C++ program for sorting the numbers

#include<stdio.h>
#include<conio.h>
#include<iostream.h>

void main()
{
    clrscr();
    int array[5];
    int p[5],i,j;
    cout<<"Enter any five numbers: "<<endl;
    for(i=0;i<=4;i++)
    {
    cin>>array[i];
    p[i]=array[i];
    }
    int temp;
    cout<<endl<<"After sorting"<<endl<<endl;
    for(i=0;i<5;i++)
    {
        for(j=i+1;j<5;j++)
        {
        if (p[i]>p[j])
            {
            temp= p[i];
            p[i]= p[j];
            p[j]= temp;
            }
        }
    }
    for(i=0;i<=4;i++)
    {
    cout<<p[i]<<" ";
    }
    getche();
}

C++ program to print star pattern

#include<iostream.h>
#include<conio.h>
void main()
{
    int i;
    clrscr();
    for (i=1;i<=9;i++)
    {
    if(i==1||i==9)
    cout<<"\n    *";
    else if(i==2||i==8)
    cout<<"\n   * *   ";
    else if(i==3||i==7)
    cout<<"\n  * * *  ";
    else if(i==4||i==6)
    cout<<"\n * * * * ";
    else if(i==5)
    cout<<"\n* * * * *";
    else
    cout<<"\n";
    }
getche();
}

C++ program to find the area of triangle using Class

#include<iostream.h>
#include<conio.h>

class triangle
{
private:
    float b ;
    float h ;
public:
    void set();
    void print();
    float area();
} ;
void triangle :: set()
    {
    cout<<"\nEnter the value of Base (then press ENTER key)  : ";
    cin>>b;
    cout<<"Enter the value of Height (then press ENTER key): ";
    cin>>h;
    }
void triangle :: print()
    {
    cout<<"\n\nFormula:";
    cout<<"\nArea of Triangle = 1/2(Base * Height)";
    }
float triangle :: area()
    {
    return 0.5*b*h ;
    }

void main()
{
    clrscr();
    cout<<"\nFinding Area of Triangle";
    cout<<"\n---------------------------";
    triangle r ;
    r.set() ;
    r.print() ;
    cout<<"\n\nResult:";
    cout<<"\nArea of Triangle = "<<r.area();
    cout<<"\n---------------------------";
    cout<<"\n\n\nPress any key to Exit";
    getche() ;
}

Saturday, 6 July 2013

C++ program to find the area of triangle

#include<iostream.h>
#include<conio.h>

void main()
{
    float b ;
    float h ;
    clrscr();   
    cout<<"\nFinding Area of Triangle";
    cout<<"\n---------------------------";
    cout<<"\nEnter the value of Base (then press ENTER key)  : ";
    cin>>b;
    cout<<"Enter the value of Height (then press ENTER key): ";
    cin>>h;
    cout<<"\n\nFormula:";
    cout<<"\nArea of Triangle = 1/2(Base * Height)";
    cout<<"\n\nResult:";
    cout<<"\nArea of Triangle = "<<b*h*0.5;
    cout<<"\n---------------------------";
    cout<<"\n\n\nPress any key to Exit";
    getche() ;
}

C++ programe to find the area of Rectangle using Class

#include<iostream.h>
#include<conio.h>

class rectangle
{
private:
    float l ;
    float w ;
public:
    void set();
    void print();
    float area();
} ;
void rectangle :: set()
    {
    cout<<"\nEnter the value of Length (then press ENTER key): ";
    cin>>l;
    cout<<"Enter the value of Width (then press ENTER key) : ";
    cin>>w;
    }
void rectangle :: print()
    {
    cout<<"\n\nFormula:";
    cout<<"\nArea of Rectangle = Length * Width";
    }
float rectangle :: area()
    {
    return l*w ;
    }

void main()
{
    clrscr();
    cout<<"\nFinding Area of Rectangle";
    cout<<"\n---------------------------";
    rectangle r ;
    r.set() ;
    r.print() ;
    cout<<"\n\nResult:";
    cout<<"\nArea of Rectangle = "<<r.area();
    cout<<"\n---------------------------";
    cout<<"\n\n\nPress any key to Exit";
    getche() ;
}

C++ programe to find the area of Rectangle

#include<iostream.h>
#include<conio.h>

void main()
{
    float l ;
    float w ;
    clrscr();   
    cout<<"\nFinding Area of Rectangle";
    cout<<"\n---------------------------";
    cout<<"\nEnter the value of Length (then press ENTER key): ";
    cin>>l;
    cout<<"Enter the value of Width (then press ENTER key) : ";
    cin>>w;
    cout<<"\n\nFormula:";
    cout<<"\nArea of Rectangle = Length * Width";
    cout<<"\n\nResult:";
    cout<<"\nArea of Rectangle = "<<l*w;
    cout<<"\n---------------------------";
    cout<<"\n\n\nPress any key to Exit";
    getche() ;
}