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.