Friday, May 24, 2013

What can PHP do?

PHP is server side web scripting language. So it is mainly work on server such as collect form data, generate dynamic page content, or send and receive cookies. 
In summarize we can say that PHP can do the following things:
  • Creating dynamic web pages
  • Collecting form data
  • Send or receive cookie
  • Insert/update records of database
  • Prevent unauthorized access
  • Decode the data(i.e. encrypt)
If we talking the about the filed/area of php working, then php also used in below category:
  1. Server Side Script: This is tradition and mostly used php filed. Here we need code-editor, server and browser(showing result). If these three thing are available in your system, then your php program run successfully.
  2. Command line script: PHP code run through command without server and browser like as DOS command. To doing this we need only PHP parser. Example: This is executed using cron(on *nix or Linux) or task scheduler(Windows).
  3. Desktop application: PHP can desktop application. But this filed is rarely used in modern era because the php is not good with desktop application.

What is PHP

The PHP stands for PHP Hypertext Preprocessor.
But in past PHP originally stands for Personal Home Page.

PHP is server side scripting language, usually used to create web applications.

PHP is invisible to the end user. So we can say that php has nothing to do with  page design(i.e. layout), events.

In summarize, we can say that "php is an open source source, server-side, HTML-embedded web-scripting language that is compatible with all the major web servers."

To run the php code, we need a server. There are two options to setup the server as:


1. Online server - It is not good for bignners and it is not free, To setup this type server, we need to purchase a hosting space where we write our code and test them online.

2. Offline server - It is good for beginners and it is 100% free to download & install and used. There are three types offline server for php as:
  1. wamp
  2. lamp
  3. xampp 
The current php version: php 5.4.15 (current stable)


Friday, May 17, 2013

Count digit repetition in number range

Q. Write a C program to count the no. of occurences of n's in a given number range.

For example:
random numbers : 45,78,2,65,489,6,2,6,55,9
find out how many times the digit 2 repeat?
2's digit repeat 2 times.

Ans.

/*c program to count the no. of occurences of n's in numbers range*/
#include<stdio.h>
int main()
{
 int arr[10],i,num,r,s,c=0;
 for(i=1; i<=10; i++)
 {
  printf("Enter %d number : ",i);
  scanf("%d"&arr[i]);
 }
 printf("\nEnter search number : ");
 scanf("%d", &s);

 for(i=1; i<=10; i++)
 {
  num = arr[i];
  while(num>=1)
  {
   r=num%10;
   if(r==s)
     c++;
   num=num/10;
  }
 }
 printf("\nThe digit %d is repeat in entered number is %d times",s,c);
 getch();
 return 0;
}

The output of above program would be:


Output of count repeate digit  in number range C program
Figure: Screen shot for count repeate digit
 in number range C program

Wednesday, May 15, 2013

Nested Pyramid

Q. Write a C program to print the following nested pyramid as:

* *** *** *
** ** ** **
*** * * ***

Ans.

/*c program for nested pyramid*/
#include<stdio.h>
int main()
{
 int r,c,num=3,n;
 n=num;
 for(r=1; r<=num; r++,n--)
 {
   for(c=1; c<=r; c++)
       printf("*");
   printf(" ");

   for(c=n; c>=1; c--)
       printf("*");
   printf(" ");
   for(c=n; c>=1; c--)
       printf("*");
   printf(" ");
   for(c=1; c<=r; c++)
       printf("*");
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of nested pyramid C program
Figure: Screen shot for nested pyramid C program

Dignal Character Pyramid

Q. Write a C program to print the following character pyramid as:

 a b b b
 b a b b
 b b a b
 b b b a

Ans.

/*c program for alternate character pyramid*/
#include<stdio.h>
int main()
{
 char r,c,ch='d';

 for(r='a'; r<=ch; r++)
 {
  for(c='a'; c<=ch; c++)
  {
    if(r==c)
       printf(" a");
    else
       printf(" b");
  }
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of dignal equal pyramid C program
Figure: Screen shot for dignal equal pyramid C program

Related program:

1. Print the following dignal number pyramid:

  1 2 2 2
  2 1 2 2
  2 2 1 2
  2 2 2 1

Alternate Number Pyramid

Q. Write a C program to print the following double number pyramid as:

1222
2122
2212
2221

Ans.

/*c program for alternate number pyramid*/
#include<stdio.h>
int main()
{
 int r,c,num=4;
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=num; c++)

  {
    if(c==r)
      printf("1");
    else
      printf("2");
  }
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of alternate number pyramid C program
Figure: Screen shot for alternate number pyramid C program

Related program:

1. Print the dignal character pyramid as:

 a b b b
 b a b b
 b b a b
 b b b a