Saturday, December 31, 2011

C Program For Pascal's Triangle - Pattern Pascal's Triangle in C Programming

It is a triangle array of the binomial coefficients. In this program input value for rows of pascal's triangle.
To get element of particular location by adding upper level(above) left value and above right value.


Program Code
//C Program to generate pascal triangle
#include"stdio.h"
#include"conio.h"
void main()
{
 int num,c,i,j,k;
 clrscr();
 printf("\nenter number of rows for pascal triangle: ");
 scanf("%d",&num);
 printf("\n\t********PASCAL TRIANGLE********\n\n");
 for(i=0;i<num;i++)
 {
  c = 1;
  for(j=0;j<num-i;j++)
  {
   printf("   ");
  }
  for(k = 0;k<=i;k++)
  {
   printf("   ");
   printf("%d",c); 
   printf(" ");
   c = c * (i - k) / (k + 1);
  }
  printf("\n");
  printf("\n");
 }
 printf("\n");
 getch();
}

Output











Wednesday, December 28, 2011

Fibonacci Series Program in Java Programming

It is a java program to generate Fibonacci series. In this program user input a number and prints the Fibonacci series for accepted number.

Java Fibonacci Series Program

Source Code
import java.lang.*;
import java.util.*;
class fibonacci
{
 public static void main(String arg[])
 {
        int a=0,b=1,c=0,i,num;
 Scanner scan = new Scanner(System.in);
 System.out.print("enter any number for fibonacci series:  ");
 num = scan.nextInt();
 System.out.println("Fibonacci Series is:"); 
 for(i=0;i<num;i++)
 {
  System.out.print(c+"\t");       
  a=b;
  b=c;
  c=a+b;
  }
 }
}

Output

In this java program create a class Fibonacci and use concept of Scanner class to accept a number from user. This program generate Fibonacci series for input.

Sunday, December 25, 2011

Java is a Platform Independent Language

Meaning of Platform Independent

It means that a program of java language must be portable to other system. Java program must be run on any hardware, machine and any operating system.
Example: java mobile games
Java mobile games runs on any multimedia mobile. When we start a java game on mobile first automatically load java runtime environment. Then mobile able to run java game independently.

Why java is a platform independent language?

Java is platform independent language. When we compile java program then it makes source file to bytecode(class file).



Bytecode is a intermediate form which is closer to machine representation. Bytecode is certain and remain same for all platforms. When compile source code(program.java) is makes bytecode(program.class). Bytecode is faster then source code.
To run bytecode to any platform there is need to load java virtual machine(JVM) interpreter.
Before run java program need JVM must be loaded into particular system. JVM makes java runtime environment into system. Bytecode makes java as platform independent compilation.


Hope, you like this post. If known further details then share to others using comments. :)

Saturday, December 24, 2011

C Program to Print Patterns of Stars

It is a sample c program to print patterns of stars.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,n,k;
printf (“Enter the value of n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-1;j++)
{
printf(“ ”);
}
for(k=1;k<=i;k++)
{
printf(“* ”);
}
printf(“\n”);
}
getch();
}

Output


Print Patterns of Stars

C Program to Print Patterns of Numbers

It is a sample c program to print patterns of numbers.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,n,k;
printf (“Enter the value of n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-1;j++)
{
printf(“ ”);
}
for(k=1;k<=i;k++)
{
printf(“1”);
}
printf(“\n”);
}
getch();
}

Output


Print Patterns of Numbers

Check Whether Given Number is Armstrong or Not in C Program

It is a sample c program to check whether given number is Armstrong or not.

Program Source Code


#include"stdio.h"
#include"conio.h"
#include"math.h"
void main()
{
int number, a , i , j , sum=0 , count=0;
clrscr();
printf(“Enter any number”);
scanf(“%d”, &number);
i=number;
j=number;
while(j>0)
{
j=j%10;
count++;
}
while(i>0)
{
a=i%10;
sum=sum + pow(a, count);
i=i/10;
}
if(sum==number)
printf(“%d is a Armstrong number”, number);
else
printf(“%d is a not Armstrong number”, number);
getch();
}

Output


Armstrong or Not in C Program

C Program to Generate Fibonacci Series

It is a sample c program to generate a Fibonacci series.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int a , b , c , i=1;
clrscr();
a=0;
b=1;
printf(“Fibonacci Series”);
printf(“%d\n”, a);
printf(“%d\n”, b);
while(i<=10)
{
c=a+b;
printf(“%d”, c);
a=b;
b=c;
i++;
}
getch();
}

Output


Generate Fibonacci Series Output

Friday, December 23, 2011

Basic Java Program To Print Hello World

It is a basic JAVA program to say to the world "Hello World". It is example for beginners to understand basic java code.
The name Java was derived at a local coffee shop frequented by some of the members and it's related to coffee material.
So In this basic program print Hello WORLD inside the coffee mug.



First install JDK(JAVA Development Kit) with latest version because to run java program need JVM(java virtual machine) when you install JDK then JVM installed in your system.
Java Virtual Machine(JVM) makes JAVA as platform independent.


Hello World JAVA Program

Program Code
class hello   //create class hello
{
  public static void main(String[] args)  //main method 
  {
    System.out.println("\nExample to print HELLO WORLD in Coffee Mug\n");
    System.out.println(" _______\n|       |\n|       |__\n| HELLO"
+" |  |\n| WORLD |  |\n|       |__|    \n|       |\n|_______|");
  }
}

Save Program
Type the program code in notepad and save Java program with classname.java. In this program save as hello.java.
File name and class name must be same.

Compile Program
javac hello.java
When compile program then it creates bytecode named with hello.class. class file created in same location where program stored.
Bytecode is a code which as same as machine language code.

Exicute the Program
java hello
Now we execute the bytecode in the Java interpreter with using this command.

Output

Friday, December 16, 2011

PL/SQL Sample Examples

Hello Friends, here discuss some sample examples related to PL/SQL programming language. These all are basic example to understand PL/SQL syntax.
I used oracle 10g during program development. There are program to understand declare statement, loop concept, procedure, function, exception handling, cursor etc.


PL/SQL Sample Examples List

1. PL/SQL Example to find average of three numbers

2. PLSQL Example Find Even Odd Number

3. PL/SQL program to generate Fibonacci series

4. Check Number is Armstrong in PL/SQL Programming

5. PL/SQL Program to reverse a string

6. Basic LOOP Program in PL/SQL

7. PLSQL FOR Loop Example

8. Reverse a Number in PL/SQL Programming

9. PL/SQL Procedure Sample Example

10. Function Example in PL/SQL Oracle

11. Exception Handling Program in PL/SQL Oracle

Hope, these sample programs help you to understand PL/SQL programming language.

Thursday, December 15, 2011

C Program to String Reverse

It is a basic C program to reverse a string.
In this c programming example user input a string and get reverse of accepted string.

Aim - C program to reverse accepted string [Using strrev function]


Program Code
//String Reverse using strrev function
#include"stdio.h"
#include"conio.h"
#include"string.h"
void main()
{
   char str[20];
   clrscr();
   printf("********* String Reverse Using strrev Function *******\n");
   printf("Enter a string:  ");
   gets(str);
   strrev(str);
   printf("\n Reverse string is:  %s",str);
   getch();
}
Output




Aim - C program to reverse accepted string [without using strrev function]


Program Code
//String Reverse without using strrev function
#include"stdio.h"
#include"conio.h"
#include"string.h"
void main()
{
 char str1[20],str2[20];
 int i,j=0;
 clrscr();
 printf("***********String Reverse*********\n");
 printf("Enter String:");
 gets(str1);
 for(i=strlen(str1)-1;i>=0;i--,j++)
 {
  str2[j]=str1[i];
 }
 str2[j]=NULL;
 printf("\nReverse String is:");
 puts(str2);
 getch();
}

Output

Why C is Called Middle Level Language?

Why C is Called Middle Level Language?

C language supports high level language which is user friendly and low level language which is machine friendly.
C combines features of a high level language with the functions of an assembly level language. It reduces the gap between low level language and high level language.
So C language called as middle level language.


C contains many features of high level language like modular programming, user friendly, loop, arrays etc. C language is also related to machine level language(low). It provides features like access to memory using pointers and assembly aspects.
C is one of the language who able to directly interact to system.
C language is used to develop both user applications and operating systems.

Thus, C is called as Middle Level Language.



Friday, December 2, 2011

C program for Bubble Sort

Today I am going to share how to perform bubble sort in C programming language. What is Bubble Sort? Bubble sort is a very simple sorting algorithm which compares consecutive numbers and swap them if both are not in right order. This gives the biggest element at the end in each inner loop cycle. Here is an animated example for bubble sort:
#include
#include

  void bubbleSort(int arr[],int length)
  {
        int i,j,temp;
         for(i=length;i>0;i--)
         {
            for(j=0;j<=i;j++)
   { 
                if(arr[j]>arr[j+1])
                { 
//swap if previous value is bigger then next value
                    temp=arr[j];
     arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
   }// End of Inner For loop
        }// End of Outer For loop.
  }// End of BubbleSort Function
  


 void main()
 {

  
  int data[] = {4,3,5,2,9,2,1,8,7,0}
  int i;

  clrscr();

  printf("\nData before sorting: ");
  
  for( i=0; i<10; i++)
  { 
   printf("%d , ",data[i]);
  }
       
  bubbleSort(data,10);

  printf("\nData after sorting: ");
  
  for( i=0; i<10; i++)
  {
   printf("%d , ",data[i]);
  }
  
  } //End of this example.

Saturday, November 26, 2011

Difference Between TCP and UDP Protocols

TCP and UDP both are transport layer protocol. They both use for process to process communication. Here I am going to discuss about "Difference Between TCP and UDP Protocols".



What is the Difference Between TCP and UDP Protocols?

1. TCP is a Transmission Control Protocol and UDP is a User Datagram Protocol.

2. TCP is a connection-oriented protocol but UDP is a connection-less protocol.
Connection-oriented means there is first establish connection before transmission and after transmission connection release.
In connection-less there is no need to call setup and call release. There is not send acknowledgement from receiver side so not detection of errors.

3. TCP is a reliable protocol but UDP is a unreliable protocol.

4. TCP packet is called as segment but UDP packet is called as datagram.

5. TCP is used for reliable and large data transfer from source to destination but UDP is used for small message transfer between stations and does not much care about reliability.

6. TCP supports error control but UDP does not support error control.

7. TCP is powerful protocol but UDP is a powerless protocol.

8. TCP is a Heavyweight protocol but UDP is a Lightweight protocol.

9. In TCP, there are control transmission of segment if any segment is loss then retransmit from source to destination but In UDP there is not retransmit loss datagram.

10. In TCP segment transfer in a sequence but In UDP there is not any sequence or order of data transmission.

11. TCP transmission speed is slower than UDP protocol.


Examples: TCP used in WWW, web services, HTTP, FTP, Telnet, IMAP etc.
UDP used in buffering of online audio and video, DNS, online games and other multimedia application where transmission speed matters more than completeness etc.

Tuesday, November 22, 2011

C Program to Swap Two Numbers

It is a sample c program to swap two number.

Program Source Code


#include"stdio.h"
#include"conio.h"
void swap(int,int);
void main()
{

int a,b;
clrscr();
printf("\n Enter value of a:-");
scanf("\n%d",&a);
printf("\n Enter value of b:-");
scanf("\n%d",&b);
printf("\n\n a before swapping is:--%d",a);
printf("\n\n b before swapping is:--%d",b);
swap(a,b);
printf("\n\n a after swapping is:--%d",a);
printf("\n\n b after swapping is:--%d",b);
getch();

}
void swap(int x,int y)
{
int t;
t=x;
x=y;
y=t;
printf("\n\n a in swapping is:--%d",x);
printf("\n\n b in swapping is:--%d",y);
}

Output


c program to swap two number

C Program to Calculate Factorial of a Number

It is a sample c program to calculate factorial of a number.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int fact=1,i,n;
clrscr();
printf("\n ***FIND THE FACTORIAL NUMBER OF ANY
NUMBER***");
printf("\n Enter the value of n:--");
scanf("\n %d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
printf("\n factorialis:-- %d",fact);
}
getch();
}

Output


Calculate Factorial of a Number

C Program to Check Largest Number in Two Variable

It is a sample C program to check largest number in two variable.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int a,b;
clrscr();
printf("***PRINT LARGEST VALUE AMONG TWO OR MORE
NUMBER***");
printf("Enter the value of a:--");
scanf("%d",&a);
printf("Enter the value of b:--")
scanf("%d",&b);
if(a>b)
{
printf("a is greater");
}
else
{
printf("b is greater");
}
getch();
}

Output


Largest Number in Two Variable in C Program

Program in C to Find Even or Odd Number

It is a sample c program to find even or odd number.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int n ;
clrscr();
printf("\n ***Check 'even' ** or ** 'odd'**** ");
printf("\n Enter the number to check:-- ");
scanf("%d",&n);
if (n%2==0)
printf("\n Given no is even:--");
else
printf("\n Given no is odd:--");
getch();
}

Output


Even or Odd Number in C Program

C Program to Check String is Palindrome or Not

It is a sample C language example. It is a string palindrome program which accept a string from user.
It checks that accepted string is a palindrome string or not. If string or string reverse is as same as then this string is a palindrome string. It means read string same in both forward or backward direction.



Aim - C program to check whether the accepted string is palindrome or not.


Program Source Code
//C Program to check accepted string is palindrome or not
#include"stdio.h"
#include"conio.h"
int isPallindrome(char *);
void main()
{
  int a;
  char str1[30];
  clrscr();
  printf("\n******String Palindrome******\n");
  printf("Enter a string: ");
  gets(str1); // accept string from user
  a=isPallindrome(str1);  /*function calls, accept string as argument and return flag value*/

  if(a)
   printf("\nstring: %s is a palindrome string",str1);
  else
   printf("\nstring: %s is not a palindrome string",str1);
  getch();

}


int isPallindrome(char *str2)
{
   int i,j,flag=1;

   for(i=0,j=strlen(str2)-1; i<j; i++, j--)
 {
    if(str2[i]!=str2[j]) /*starts checking from ends of string to middle*/
  {
    flag=0; /*if reverse of string is not same than return 0*/
    break;
  }

 }
   return(flag);
}


Output1
******String Palindrome******
Enter a string: MADAM
string: MADAM is a palindrome string

Output2
******String Palindrome******
Enter a string: HELLO
string: HELLO is not a palindrome string




Sunday, November 20, 2011

Sample resume for freshers

Hi Guys, This it the time of campus recruitment and many final year and pre final year students are looking for resume. Here I am sharing a sample resume for fresher. If you are fresher then this format will help you for initiating your resume. This very simple resume style with all basic details. Sample Resume for Freshers

Please share other resume formats with us. Thank you.

C Program to Find Armstrong Series

It is a sample c program to generate Armstrong number series from 1 to 1000. 

Program Source Code

//C Program to Find All Armstrong Number between 1 to 1000. #include"stdio.h" #include"conio.h" void main() { int no,r,sum=0,i; clrscr(); printf("\n\n***The Armstrong No. Series Between 1 and 1000 are:*** "); for(i=1;i<=1000;i++) { sum=0; no=i; while(no!=0) { r=no%10; no=no/10; sum=sum+(r*r*r); } if(sum==i) printf("\n%d",i); } getch(); }
Output








Saturday, November 19, 2011

C Program for Check Armstrong Number

It is a sample C program to find accepted number is Armstrong number on not.


Program Source Code
//Write a program to check accepted number is armstrong number or not.
#include"stdio.h"
#include"conio.h"
void main()
{
  int i,no,r,sum=0;
  clrscr();
  printf("*******Armstrong Number******");
  printf("\n Enter a number");
  scanf("%d",&no);
  i=no;
  while(no!=0)
   {
    r=no%10;
    sum=sum+(r*r*r);
    no=no/10;
   }
   if(sum==i)
    printf("Number is a Armstrong number\n");
   else
    printf("Number is not a armstrong number\n");
   getch();
}


Output







Find Fibonacci Series Using Recursion in C Programming

It is sample C program which demonstrate how to use recursion concept in c programming. Here is a recursion program which accept a number from user and generate Fibonacci series using recursion.

Program Code
//Find Fibonacci Series Using Recursion in C Programming
#include"stdio.h"
#include"conio.h"
fibonacci(int n);
void main()
{
 int n,r,i;
 clrscr();
 printf("********** Fibonacci Series Using Recursion *********\n");
 printf("enter a number: ");
 scanf("%d",&n);
 printf("\n\n");

 for(i=0;i<=n;i++)
 {
  r=fibonacci(i);
  printf("\t%d",r);
 }
 getch();
}

fibonacci(int n)
{
 int f;
 if((n==1)||(n==2))
  return(1);
 else if(n==0)
  return(0);
 else
  f=fibonacci(n-2)+fibonacci(n-1);
 return(f);
}
Output






C Program With Recursion: Find Factorial Using Recursion in C Programming

It is a sample program example which demonstrate recursion in C programming. It is a factorial program with recursion. Accept number from the user and generate factorial of accepted number using recursion.

Program Code
#include"stdio.h"
#include"conio.h"
fact(int n);
void main()
{
 int n,r;
 clrscr();
 printf("************* Find Factorial of Number Using Recursion *************");
 printf("\n enter a number ");
 scanf("%d",&n);
 r=fact(n);
 printf("\n Factorial of %d is =  %2d\t",n,r);
 getch();
}

fact(int n)
{
 int f;
 if((n==0)||(n==1))
  return(1);
 else
  f=n*fact(n-1);
 return(f);
}



Output

Friday, November 18, 2011

Function Example in PL/SQL Oracle

It is a sample pl/sql oracle example which have a function cube1 and a program. When a function calls accepted number(no) from user is passed as a argument and output of cube1 function is return value to variable(res).


Aim - PL/SQL program to accept a number from user and display its cube(num^3) value using function.


Function:-
First Execute Function PL/SQL block
create or replace function cube1(no in number) return number IS result number(8);
begin
  result:=(no*no*no);
  return result;
exception
  when no_data_found then
  return 'error';
end;


Program: -
Second Execute PL/SQL Program
declare
 no number(5);
 res number(10);
begin
  no:=&no;
  res:=cube1(no);
  dbms_output.put_line('Cube of ' || no || ' is '|| res);
end;


Output: -
Enter value for no: 6
old 5: no:=&no;
new 5: no:=6;
Cube of 6 is 216

Exception Handling Program in PL/SQL Oracle

It is a sample PL/SQL Oracle exception handling program to handle errors. It is used for error tolerance and error avoidance.
In Pl/SQL exception is used to handle run time errors. When a run time error occurs then it moves to exception handler block in PL/SQL program.


Aim -PL/SQL program to perform exception handling.


Program: -
declare
  empn emp.empno%type;
  row_type1 emp%rowtype;
begin
  empn:=&empn;
  select * into row_type1 from emp where empno=empn;
  dbms_output.put_line('Name: '||row_type1.ename);
  exception when NO_DATA_FOUND then
  dbms_output.put_line('No such employee');
end;


Output: -

Enter value for empn: 7566
old 5: empn:=&empn;
new 5: empn:=7566;
Name: JONES

Enter value for empn: 1001 /* Such employee number(empno) is not in emp table */
old 5: empn:=&empn;
new 5: empn:=1001;
No such employee




PL/SQL Procedure Sample Example

It is a sample PL/SQL Oracle example using procedure.
When create a procedure IN and OUT keyword used during pass parameters. IN is used to pass values to the procedure and OUT is used to return values to the caller.

Aim - PL/SQL Oracle program to add two numbers using procedure.


Procedure: -
create or replace procedure add_proc(n1 IN number,n2 IN number, tot OUT number)as
begin
tot:=n1+n2;
end;

Sample Program Code: -
declare
 num1 number(3);
 num2 number(3);
 result number(4);
begin
 num1:=&num1;
 num2:=&num2;
 add_proc(num1,num2,result);
 dbms_output.put_line('Addition is: '||result);
end;

First execute only the PL/SQL procedure part then fire program. In this program first execute the add_proc procedure than execute the PL/SQL program.


Output: -
When Execute Procedure then we get output like:
Procedure created.


When Execute Program then:
Enter value for num1:
old 6: num1:=&num1;
new 6: num1:=23;
Enter value for num2: 34
old 7: num2:=&num2;
new 7: num2:=34;
Addition is: 57

Thursday, November 17, 2011

Check Number is Armstrong in PL/SQL Programming

It is a sample pl/sql program to take input a number from user and it checks accepted number is Armstrong or not.

Aim - PL/SQL program to check whether number is Armstrong or not.

Program:-
declare
  pnum number(5);
  tot number(5);
  lp number(3);
  tmp number(5);
begin
  pnum:=&pnum;
  tmp:=pnum;
  tot:=0;
  while tmp>0
  loop
    lp:=tmp mod 10;
    tot:= tot + (lp*lp*lp);
    tmp:=floor(tmp/10);
  end loop;
  if(tot like pnum) then
    dbms_output.put_line(pnum||' is armstrong.');
  else
    dbms_output.put_line(pnum||' is not armstrong.');
  end if;
end;


Output: -
Enter value for pnum: 153
old 7: pnum:=&pnum;
new 7: pnum:=153;
153 is armstrong.

Reverse a Number in PL/SQL Programming

It is a sample PL/SQL program to take input a number form user and print reverse of accepted number.

Aim - PL/SQL Program to accept a number from user and print number in reverse order.

Program: -
declare
  num1 number(5);
  num2 number(5); 
  rev number(5);
begin
  num1:=&num1;
  rev:=0;
  while num1>0
  loop
    num2:=num1 mod 10;
    rev:=num2+(rev*10);
    num1:=floor(num1/10);
  end loop;
  dbms_output.put_line('Reverse number is: '||rev);
end;


Output: -
Enter value for num1: 12345
old 8: num1:=&num1;
new 8: num1:=12345;
Reverse number is: 54321



Basic LOOP Program in PL/SQL

It is a PL/SQL program which show how to use basic loop concept in PL/SQL block.

Aim - PL/SQL program to print 1 to 10 using basic loop.


Sample Program: -
declare
  num number(3);
begin
  num:=1;
  loop
     dbms_output.put_line(num);
     num:=num+1;
     exit when num>10;  
  end loop;
end;

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

PLSQL FOR Loop Example

It is a basic FOR loop example program which is demonstrate how to use FOR loop in PL/SQL block. FOR loop use in PLSQL is quite differ with C program FOR loop syntax. In PLSQL you should specify the range of integer to execute the sequence of statements.

Syntax
FOR variable IN start..end
LOOP
 PL/SQL block statements
END LOOP;


Sample Example to print number 1 to 10 using FOR loop.

Aim - pl/sql program to print 1 to 10 using FOR loop


Program Code: -
declare
  num number(3);
begin
  for num in 1..10
 loop
  dbms_output.put_line(num);
 end loop;
end;


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



Another example to print 1 to 10 in reverse order using FOR loop.
Syntax
FOR variable IN REVERSE start..end
LOOP
PL/SQL block statements
END LOOP;



Aim - program to print 1 to 10 in reverse order using FOR loop.

Program Code: -
declare
  num number(3);
begin
  for num in  REVERSE 1..10
 loop
  dbms_output.put_line(num);
 end loop;
end;


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

Wednesday, November 16, 2011

PLSQL Example Find Even Odd Number

It is a sample plsql example code to find accepted number is even or odd and print output with friendly message.

Even or Odd Number
Even number is a number which is completely divided by 2 and reminder is 0 like 2, 4, 6, 8, 10, ..
Odd number is a number which is completely not divided by 2 and reminder is not 0 like 1, 3, 5, 7, 9, ..


Aim - PLSQL Example to find accepted number is even or odd


Program Code : -

declare
  num number(5);
begin
  num:=&num;
  if num mod 2 =0 then
    dbms_output.put_line('Accepted Number '||num||' is even');
  else
    dbms_output.put_line('Accepted Number '||num||' is odd');
  end if;
end;



Output of PLSQL Block:-
Enter value for num: 10
old 5: num:=&num
new 5: num:=10;
Accepted Number 10 is even


Saturday, November 12, 2011

PL/SQL Example to find average of three numbers

This is a PL/SQL sample example to accept three numbers from the user and find average of accepted numbers.

Aim - PL/SQL Example to find average of three numbers



Sample Program : -


declare
a number(3);
b number(3);
c number(3);
avgr number(5,2);
begin
a:=&a;
b:=&b;
c:=&c;
avgr:=((a+b+c)/3);
dbms_output.put_line('Average of a, b, c is: '||avgr);
end;


Output of PL SQL Block: -

Enter value for a: 22
old 7: a:=&a;
new 7: a:=22;
Enter value for b: 32
old 8: b:=&b;
new 8: b:=32;
Enter value for c: 43
old 9: c:=&c;
new 9: c:=43;
Average of a, b, c is: 32.33

PL/SQL program to generate Fibonacci series

It is a sample example of generate fibonacci series upto 10 numbers.

Aim - PL/SQL program to generate Fibonacci series.



PLSQL Sample Program: -

declare
f1 number(3);
f2 number(3);
f3 number(3);
num number(3);
begin
f1:=0;
f2:=1;
f3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(f3);
f1 :=f2;
f2:=f3;
f3:=f1+f2;
num:=num+1;
end loop;
end;




Output of PL SQL Block: -
0
1
1
2
3
5
8
13
21
34

PL/SQL Program to reverse a string

This is a sample PLSQL example to accept a string from user and print reverse of accept string.

Aim - PL/SQL Program to reverse a string.



Sample PLSQL Program: -
declare
str1 varchar2(30);
len number(3);
str2 varchar2(30);
i number(3);
begin
str1:='&str1';
len:=length(str1);
for i in reverse 1..len
loop
str2:=str2 || substr(str1,i,1);
end loop;
dbms_output.put_line('Reverse string is: '||str2);
end;




Output of PL SQL Block: -
Enter value for str1: hello
old 6: str1:='&str1';
new 6: str1:='hello';
Reverse string is: olleh

Sunday, September 25, 2011

Multipath Inheritance in CPP

Hello friends, today I am going to discuss on one type of inheritance in c++. This is "Multipath Inheritance in CPP". Here also discuss about problem in multipath inheritance and how to solve this problem. Multipath Inheritance explains by using a sample c++ example.

What is Multipath Inheritance?

Multipath Inheritance is a hybrid inheritance. It is also called as Virtual Inheritance. It is combination of hierarchical inheritance and multiple inheritance.
In Multipath Inheritance there is a one base class GRANDPARENT. Two derived class PARENT1 and PARENT2 which are inherited from GRANDPARENT. Third Derived class CHILD which is inherited from both PARENT1 and PARENT2.

Problem in Multipath Inheritance

There is an ambiguity problem. When you run program with such type inheritance. It gives a compile time error [Ambiguity]. If you see the structure of Multipath Inheritance then you find that there is shape like Diamond.

Multipath Inheritance

Why Ambiguity Problem in Virtual Inheritance?

Suppose GRANDPARENT has a data member int i. PARENT1 has a data member int j. Another PARENT2 has a data member int k. CHILD class which is inherited from PARENT1 and PARENT2. It has a data member int l.
CHILD class have data member
int l(CHILD class data member)
int j( one copy of data member PARENT1)
int k ( one copy of data member PARENT2)
int i(two copy of data member GRANDPARENT)

This is ambiguity problem. In CHILD class have two copies of Base class. There are two duplicate copies of int i of base class. One copy through PARENT1 and another copy from PARENT2. This problem is also called as DIAMOND Problem.

Solve Multipath Inheritance Problem

To avoid duplicate copies of class Base we inherited intermediary classes with the prefix of the keyword "virtual". We use virtual keyword so it is also called as "Virtual Inheritance".
This results is avoiding duplicate copies of class Base members and in child class have only one copy of base class members.

C++ Program to demonstrate Multipath Inheritance

#include < iostream.h >
#include < conio.h >
class A
{
public:
int a;
};
class B: virtual public A
{
public:
int b;
};
class C: virtual public A
{
public:
int c;
};
class D:public B,public C
{
private:
int d;
public:
void sum()
{
d=a+b+c;
}
void display()
{
cout<<"Sum of a,b,c is:  " << d ;  
}  
}; 
void main() 
{  
D d1;  
clrscr();  
d1.a=10;  
d1.b=20;  
d1.c=30;  
d1.sum();  
d1.display();  
getch(); 
}  

Output


when not using virtual keyword as prefix for intermediary class
Compile time error
Member is ambiguous: A::a and A::a

Output When use keyword virtual as prefix intermediary class
Sum of a,b,c =60

Hope, you like this post. If anybody known further details about multipath inheritance then share to others by comments.

Saturday, September 10, 2011

Difference Between C and C++ Programming

Difference Between C and C++ Programming


difference C and C++















C ProgrammingC++ Programming
C follows the procedural programming paradigmC++ is a multi-paradigm language(procedural as well as object oriented)
In C language focus on procedure and steps.C++ focuses on the data rather than the process
In C data hiding and data security is not possible.Data hiding and data security is present.
C uses Top-Down approchC++ uses Bottom-Up approach
C is a function driven programming languageC++ is a object driven programming language
C does not support overloading conceptC++ supports overloading concepts like operator overloading and function overloading
C does not support namespaces conceptCPP supports Namespaces concept.
C not support exception handlingC++ supports Exception Handling
C is structured programming languageC++ is object oriented programming language.
C does not support inheritance, reusability, polymorphism, data abstractionCPP supports inheritance, reusability, polymorphism, data abstraction.
C language only support Early bindingCPP supports both Early and Late binding
C uses standard input, output functions like scanf and printf.C++ uses input function cin and output function is cout.
There are all data is available to end user. No data securityThere is data abstraction. Not complete data is available to End user

C and C++

Sunday, September 4, 2011

C program for Binary Search

Hello, Today I am sharing how to implement Binary Search in C Programming 
language. Here is the basic algorithm for binary search:


C program for binary search :

#include<stdio.h>

int main(){
  int a[8];
  int i,x,first,last,mid;

printf("\nEnter 8 sorted elements like 
               [2 4 7 9 12 13 16 20]");
for(i=0;i<8;i++)
{
scanf("%d",&a[i]);
}
printf("\nYou entered following numbers:");
for(i=0;i<8;i++){
printf(" %d",a[i]);
}
printf("\nEnter the number you want to search: ");
scanf("%d",&x);
  
first=0,last=n-1;
while(first<=last){
      mid=(first+last)/2;
      
 if(x==a[mid]){
printf("\nThe number is found at %d", mid);
        return 0;
      }
      else if(x<a[mid]){
last=mid-1;
      }
      else
first=mid+1;
}

    printf("\nThe number is not in the list");

return 0;

}


I hope you this post is helpful for you. Thanks for reading.





Saturday, September 3, 2011

How to send email using PHP on WAMP

Hello guys, Today I was trying to fix my friends code problem, He was just trying to send email using php which was running on WAMP Server. Then I recollected this details and shared with him. Here is the step by step guide:

PHP Code for sending an email using mail() function :

<?php
 $toAddress = "user@sampleexamples.com";
 $emailSubject = "Sample Email";
 $emailBody = "Hello,\n\n\nJust Tesing This Code?";
 if (mail($
toAddress
, $
emailSubject 
, $
emailBody
)) {
echo("<p>Email successfully sent!</p>"); } else { echo("<p>Error: Email delivery failed...</p>"); } ?>



Configuration in php.ini :
To make the above coe work, you have to set few value in your php.ini of your WAMP installation. Its quit easy to do this, just find your php.ini and replace the default values with the appropriate . 


; For Win32 only.
SMTP = mail.example.come ; for Win32 only
smtp_port = 25
sendmail_from= admin@example.com ; for Win32 only

Now you can use this code for sending emails using your php server which is running either on localhost or on some live domain.

I hope this information is helpful to you. Please share your comments.
Thanks for reading.

Hello World program in Java


Here is the basic java program which will help java beginners.
In every programming language when we initially starts learning,
we always find the "Hello World" program in books.
So in java same program is the first step for you to start with.


Here is the sample "Hello World" Program:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}


Please follow these steps to compile and execute this HelloWorld program.
  1. Open notepad or any type of text editor.
  2. Copy and paste above code into that text editor.
  3. Save that file and named it as "HelloWorld.java"
  4. Goto command prompt and compile this program using javac command 
    • c:\path\to\file\>javac HelloWorld.java
    • This will generate a HelloWorld.class file
  5. Now for executing that class file you have to issue following java command
    • c:\path\to\file\>java HelloWorld
  6. You will see Hello, World as the output.
I hope this post helped you in your learning. Please ask your questions by comments.

How to use document.write in JavaScript?


Hello guys, Today I am sharing very basic method of javascript which is "document.write()".
Using document.write you can write inside a html document using javascript.

A very basic hello world example is below:

<script type="text/javascript">
document.write("<p>Hello World</p>");
</script>


To understand document.write function in more depth, I am sharing few more simple usage of this function.

<script type="text/javascript">
var sampleText="Sample Example of Document.write function";
document.write("<p>"+sampleText+"</p>");
</script>

Printing date using document.write function:

<script type="text/javascript">
var sampleText="Sample Example of Document.write function";
document.write("<p>"+Date()+"</p>");
</script>


Using document.write function inside a function:

<script type="text/javascript">
function f1() {
document.write('hello world');
}
</script>

<script type="text/javascript">
f1();
document.write('Ba Bye');
</script>


Overriding whole document's content using document.write function:
<script type="text/javascript">
function f1() {
document.write('Some text');//for overwrite entire page content
}
window.onload = w1;
</script>



I hope you like this post. Please share your feedback by commenting below.