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