Wednesday, June 15, 2011

Binary Tree (JAVA implementation)

In computer science, a binary search tree, which may sometimes also be called an ordered or sorted binary tree, is a node-based binary tree data structure which has the following properties:
  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.
Generally, the information represented by each node is a record rather than a single data element. However, for sequencing purposes, nodes are compared according to their keys rather than any part of their associated records.

wikipedia Article

/**
 * @author rajeevan
 */
public class BinaryTree <Key extends Comparable<? super Key>> {
   
    private Node root;
   
    class Node{
        private Key value;
        private Node left;
        private Node right;
       
       
        public Node(Key key){
            this.value=key;
        }
       
        public Node(Key key,Node left,Node right){
            this(key);
            this.left=left;
            this.right=right;
        }
       
        @Override
        public String toString(){
            return "value="+value+ " left="+left+" right="+right;
        }
       
        public void setLeft(Node left){
            this.left=left;
        }
       
        public void setRight(Node right){
            this.right=right;
        }
       
        public void setValue(Key value){
            this.value=value;
        }
       
        public Node getRight(){
            return right;
        }
       
        public Node getLeft(){
            return left;
        }
       
        public Key getValue(){
            return value;
        }
    }
  
    //create new binary tree starting with the root value
    public BinaryTree(Key value){
        this.root =new Node(value);
    }
   
    //create new binary tree with empty root
    public BinaryTree(){
       
    }
   
    //add a value to the binary Tree
    public void addValue(Key value){
        this.root=insertValue(value, root);
    }
   
    private Node insertValue(Key value,Node node){
    
        int compare=node.getValue().compareTo(value);

        if(compare==0){
            return node;
        }else if(compare>0){
            if(node.getLeft()!=null){
                node.setLeft(insertValue(value, node.getLeft()));
            }else{
                node.setLeft(new Node(value));
            }
        }else if(compare<0){
            if(node.getRight()!=null){
                node.setRight(insertValue(value, node.getRight()));
            }else{
                node.setRight(new Node(value));
            }
        }
        return node;
    }
   
    //search the tree for a value
    public boolean searchTree(Key value){
        return this.searchTree(value,root);
    }
   
    private boolean searchTree(Key value,Node node){
       
        if(node==null){
            return false;
        }

        if(node.getValue().equals(value)){
            return true;
        }else if(node.getValue().compareTo(value)<0){
            return searchTree(value,node.getRight());
        }else if(node.getValue().compareTo(value)>0){
            return searchTree(value, node.getLeft());
        }else{
            return false;
        }
    }
   
    public Key findMin() {
    return this.findMin(root);
    }

    private Key findMin(Node node){
        if(node.getLeft()==null){
            return node.getValue();
        }else{
            return findMin(node.getLeft());
        }
    }
   
    //return the minimum value of the tree
    public Key findMax() {
        return this.findMax(root);
    }

    private Key findMax(Node node){
        if(node.getRight()==null){
            return node.getValue();
        }else{
            return findMax(node.getRight());
        }
    }
   
    public void removeValue(Key value){
        this.removeValue(value,root);
    }
   
    private Node removeValue(Key value,Node node){
       if(node.getValue().compareTo(value)>0){
            node=removeValue(value,node.getLeft());
        }else if(node.getValue().compareTo(value)<0){
            node=removeValue(value,node.getRight());
        }else if(node.getLeft()!=null&& node.getRight()!=null){
             Key max=this.findMax(node.getLeft());
             node.setValue(max);
             node.setLeft(this.removeValue(max,node.getLeft())) ;
            
        }else{
            if(node.getLeft()==null&&node.getRight()==null){
                node=null;
            }else{
            Key k=node.getLeft()==null?node.getRight().getValue():node.getLeft().getValue();
            node.setValue(k);
            }
        }
        return node;
    }
   
   
}

Sunday, May 22, 2011

Maze Traversal

A common problem in AI(Artificial Intelligent) is solving a Maze. There are number of algorithms to solve different type of mazes and number of Algorithms to create a random maze of a particular type.

there are number of types of mazes. They are classified according to Dimension, Hyper dimension, Topology, Tessellation, Routing, Texture, and Focus. Each have its own properties.

For more Details on Algorithms to Solve Maze go Here
for types of Mazes and maze generation and solution algorithms click here

Below I generate a random maze with Recursive backtracking and Solve it almost same algorithm call wall follower.
The basic idea of the solution is You just place your Right hand on the right side wall and just go until find the exit point. This will eventually guide you to the exit point. this method will suitable for any type of 2D Mazes but it is a little bit slow compared to other methods.

#################################################


#include <stdio.h>
#include <stdlib.h>
#include   <time.h>

#define WALL 1
#define BORDER 2
#define PATH 3

#define TEMPSOL 4
#define SOL 5

#define START 0
#define END 6

#define SIZE 30

void printMaze(int floor[][SIZE]);
void generateMaze(int floor[][SIZE],int start[]);
void solveMaze(int floor[][SIZE],int start[]);

int main(int argc, char** argv) {

    int floor[SIZE][SIZE];

    int start[2]={1,1};
    generateMaze(floor,start);
    printMaze(floor);
   
    solveMaze(floor,start);
    printMaze(floor);

    return (EXIT_SUCCESS);
}


void printMaze(int floor[][SIZE]){
    printf("\n");
    int i;
    int j;
    for(j=SIZE-1;j>=0;j--){
        for(i=0;i<SIZE;i++){
            switch(floor[i][j]){
                case BORDER:
                    printf("##");
                    break;
                case WALL:
                    printf("WW");
                    break;
                case PATH:
                    printf("  ");
                    break;
                case START:
                case TEMPSOL:
                    printf("ST");
                    break;
                case END:
                    printf("EX");
                    break;
                case SOL:
                    printf("* ");
                    break;
            }
        }
        printf("\n");
    }
}

void solveMaze(int floor[][SIZE], int start[]){
    int recursiveSolve(int floor[][SIZE],int position[]);
    recursiveSolve(floor,start);
    floor[start[0]][start[1]]=START;

}

void generateMaze(int floor[][SIZE],int startPosition[]){
    void recursiveBackTrack(int floor[][SIZE],int position[]);

    //initialize Maze Arena
    int i;
    int j;
    for(i=0;i<SIZE;i++){
        for(j=0;j<SIZE;j++){
            floor[i][j]=BORDER;
        }
    }
    for(i=1;i<SIZE-1;i++){
        for(j=1;j<SIZE-1;j++){
            floor[i][j]=WALL;
        }
    }

    //set the StartPosition
    srand(time(NULL));
    recursiveBackTrack(floor,startPosition);
    floor[startPosition[0]][startPosition[1]]=START;
    //set the EndPosition
    int endPosition[2]={SIZE-2,SIZE-2};
    floor[endPosition[0]][endPosition[1]]=END;
}

int  recursiveSolve(int floor[][SIZE],int currentPosition[]){
    int neighbour[4][3]={{floor[currentPosition[0]+1][currentPosition[1]],currentPosition[0]+1,currentPosition[1]},       //right
                             {floor[currentPosition[0]][currentPosition[1]+1],currentPosition[0],currentPosition[1]+1},       //up
                             {floor[currentPosition[0]-1][currentPosition[1]],currentPosition[0]-1,currentPosition[1]},       //left
                             {floor[currentPosition[0]][currentPosition[1]-1],currentPosition[0],currentPosition[1]-1}};      //down
   
    int i;
    if(floor[currentPosition[0]][currentPosition[1]]==END){
        return 1;
    }else{
        for(i=0;i<4;i++){
            if(neighbour[i][0]==PATH||neighbour[i][0]==END){
                 int t[2]={neighbour[i][1],neighbour[i][2]};
                floor[currentPosition[0]][currentPosition[1]]=TEMPSOL;
                if(recursiveSolve(floor,t)==1){
                    floor[currentPosition[0]][currentPosition[1]]=SOL;
                    return 1;
                }
            }
        }
        floor[currentPosition[0]][currentPosition[1]]=PATH;
        return 0;
    }

}

void recursiveBackTrack(int floor[][SIZE],int currentPosition[]){
    int checkPositions(int floor[][SIZE],int position[],int comingFrom);
    floor[currentPosition[0]][currentPosition[1]]=PATH;

   
    int eachDirection[4][2]={{currentPosition[0]+1,currentPosition[1]},       //right
                             {currentPosition[0],currentPosition[1]+1},       //up
                             {currentPosition[0],currentPosition[1]-1},      //down
                             {currentPosition[0]-1,currentPosition[1]}};       //left
                            

   
    int directions[4]={0,1,2,3};
    int i;
   
    for(i=4;i>0;i--){
        int randomDirection=rand()%i;
        int tempDirection=directions[randomDirection];
        directions[randomDirection]=directions[i-1];
        if(checkPositions(floor,eachDirection[tempDirection],(3-tempDirection))==1){
            recursiveBackTrack(floor,eachDirection[tempDirection]);
        }
    }

}

int checkPositions(int floor[][SIZE],int position[],int comingFrom){
    int eachDirection[4][2]={{position[0]+1,position[1]},       //right
                             {position[0],position[1]+1},       //up
                             {position[0],position[1]-1},      //down
                             {position[0]-1,position[1]}};       //left
   
    if(floor[position[0]][position[1]]==WALL){                     //check weather the cell is unused
        int i;
        for(i=0;i<4;i++){
            if(i!=comingFrom && floor[eachDirection[i][0]][eachDirection[i][1]]==PATH){      //skip the previous cell &&
                    return 0;
            }
        }     
        return 1;
    }else{
        return 0;
    }
}


Tuesday, May 17, 2011

Find Palindrome

A palindrome is a word, phrase number or other sequence of units that can be read the same way in either direction
Eg:
Was it a rat I saw.     A nut for a jar of tuna.     Doc note I dissent A fast never prevents a fatness I diet on cod.    A man a plan, a canal Panama
here i try a recursive solution to find weather a sentence is a palindrome.
my solution is case sensitive and exclude spaces.
########################################################################
#include <stdio.h>
#include <stdlib.h>

int testPalindrome(char data[],int start,int end);
int main(int argc, char** argv) {
char string[]="a man a plan a canal panama";
//was it a rat I saw
//a nut for a jar of tuna
//dammit I m mad
//doc note i dissent a fast never prevents a fatness I diet on cod
int size=0;
char c;
while(c!=''){
c=string[size];
printf("%c",c);
size++;
}
printf("\n\n");
if(testPalindrome(string,0,size-2)==1){
printf("this is a Palindrome\n");
}else{
printf("this is not a Palindrome\n");
}
return (EXIT_SUCCESS);
}
int testPalindrome(char data[],int start,int end){
int i=1;
if(start>=end){
return 1;
}else if(data[start]==' '){
start++;
i=testPalindrome(data,start,end);
}else if(data[end]==' '){
end--;
i=testPalindrome(data,start,end);
}else if(data[start]==data[end]){
i=testPalindrome(data,(start+1),(end-1));
}else{
return 0;
}
return i;
}

Bucket Sort

A bucket sort begins with single subscripted array of positive integers to be sorted and a double subscripted array of integers with rows subscripted from 0 to 9 and columns subscripted from 0 to n-1 where n is the number of values in the array to be sorted.
Algorithm
1. Loop through the single subscripted array and place each of its values in a row of the bucket array based on its ones dight.
2.loop through bucket array. copy each element and past it in data array.
3.Repeat the process for each subsequent positions (tens, hundreds,thousands)
Note:
double subscripted array (bucket ) is 10 times larger than data array. which consume a considerable amount of memory. but its performance is high compared to bubble sort.
##############################################################
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define SIZE 20
#define MAXLENGTH  3        //MAXLENGTH means the number of numbers in a value
//eg. max value in data 9999 then  MAXLENGTH 4
void printArray(int data[]){
int i;
int j;
printf("\n\n");
for(i=0;i<SIZE;i++){
printf("%d \n",data[i]);
}
}
int main(int argc, char** argv) {
int data[SIZE];
int tmpArray[SIZE][10];
int tmpData[10]={0};
//Array initialization
srand(time(NULL));
int i;
for(i=0;i<SIZE;i++){
data[i]=rand()%((int)pow(10,MAXLENGTH));
printf("%d \n",data[i]);
}
//sorting
int power;
for(power=10;power<=(int)pow(10,MAXLENGTH);power*=10){
int j;
for(j=0;j<SIZE;j++){
int bal=data[j]%power;
bal=(int)(((10*bal)/power));
tmpArray[tmpData[bal]][bal]=data[j];
tmpData[bal]++;
}
int l;
for(j=0,l=0;j<10;j++){
int k;
for(k=0;k<tmpData[j];k++,l++){
data[l]=tmpArray[k][j];
}
tmpData[j]=0;
}
}
printArray(data);
return (EXIT_SUCCESS);
}

Eight Queens

Is it Possible to place eight queens on an empty chessboard so that no queen is "attacking" any other?
Here i Try to solve/ design a simple puzzle game.
you can enter position of the queen like 1,1 or 3,5 or 8,8
it will place the queen on the board if it is legal and a table will show with numbers to each square of the chessboard indicating how many squares of an empty chessboard are 'eleminated' once a queen is placed in that square.
The appropriate heuristic might be: Place the next queen in the square with the smallest elemination number.
######################################################################

#include <stdio.h>
#include <stdlib.h>

void placeQueen(int board[][8][3],int position[]);
int  isLegal(int board[][8][3],int position[]);
void printBoard(int board[][8][3],int layer);
void calcBestPlace(int board[][8][3]);

int main(int argc, char** argv) {
int board[8][8][3]={};
//board
//first layer:  places of queen
//second layer: attacking positions
//thrid layer:  hint with minimum attacking positions
int x;
int y;
int i;
calcBestPlace(board);
printBoard(board,2);
for(i=0;i<8;i++){
scanf("%d,%d",&x,&y);
int a[]= {x-1,y-1};
if(isLegal(board,a)==1){
printf("is legal\n");
placeQueen(board,a);
calcBestPlace(board);
printBoard(board,0);
printBoard(board,2);
}else{
printf("Illegal Place for Queen\n");
printBoard(board,1);
i--;
}
}
return (EXIT_SUCCESS);
}
void placeQueen(int board[][8][3],int position[]){
board[position[0]][position[1]][0]=1;
int i;
int j;
int k;
//fill attacking positions
for(i=0;i<8;i++){
for(j=0;j<8;j++){
if(((position[0]-i)==(position[1]-j))||position[0]==i||position[1]==j||(position[0]-i)==(j-position[1])){
//printf("position=%d,%d and i=%d,j=%d\n",position[0],position[1],i,j);
board[i][j][1]=1;
}
}
}
}
int isLegal(int board[][8][3],int position[]){
if(board[position[0]][position[1]][1]==1){
return 0;
}else{
return 1;
}
}
void printBoard(int board[][8][3],int layer){
int i;
int j;
switch(layer){
case 0:
case 1:
for(j=7;j>=0;j--){
for(i=0;i<8;i++){
if(board[i][j][layer]==1){
printf("Q   ");
}else{
printf("+   ");
}
}
printf("\n\n");
}
break;
case 2:
for(j=7;j>=0;j--){
for(i=0;i<8;i++){
printf("%2d ",board[i][j][2]);
}
printf("\n");
}
}
}
void calcBestPlace(int board[][8][3]){
int i;
int j;
int x;
int y;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
board[i][j][2]=0;
if(board[i][j][1]==1){
continue;
}else{
for(x=0;x<8;x++){
for(y=0;y<8;y++){
if(((x-i)==(y-j))||x==i||y==j||((x-i)==(j-y))){
if(board[x][y][1]!=1){
board[i][j][2]++;
}
}
}
}
}
}
}
}

Thursday, April 21, 2011

Recursive Solution for Tower of Hanoi

The Tower of Hanoi or Towers of Hanoi , also called the Tower of Brahma or Towers of Brahma, is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
Tower of Hanoi
The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:
  • Only one disk may be moved at a time.
  • Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
  • No disk may be placed on top of a smaller disk.
Source:- wikipedia.org
Solution
/////////////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
void solveTOH(int x,int y, int z);
int main(){
int input;
printf("enter the number of pegs:");
scanf("%d",&input);
printf("goint to solve %d number of disks\n\n",input);
solveTOH(input,1,3);
return 0;
}
void solveTOH(int noOfDisks,int initial,int toTransfer)     // initial: transfer disks from which tower
//toTransfer: transfer disks to which tower
{
int temp;
if(initial!=3&&toTransfer!=3){
temp=3;
}else if(initial!=2&&toTransfer!=2){
temp=2;
}else{
temp=1;
}
if(noOfDisks!=1){
solveTOH(noOfDisks-1,initial,temp);
printf("moving %d from %d----->%d\n",noOfDisks,initial,toTransfer);
solveTOH(noOfDisks-1,temp,toTransfer);
}else{
printf("moving %d from %d----->%d\n",noOfDisks,initial,toTransfer);
}
}

Saturday, March 12, 2011

Knight's Tour

One of the more interesting puzzlers for chess buffs is the Knight's Tour Problem, originally proposed by mathematician Euler. The question is this: Can the chess piece called the knight move around an empty chessboard and touch each of the 64 squares once and only once?

knights tour
Knight's tour
You can learn some algorithms to solve the problem here
Here I include the source code for a small Game using number keys(1,2,3,4,5,6,7,8) to move knights to eight positions around it.
1 :   Up 2  and Right 1
2:    Up 2 and  Left   1
3:   Left 2 and  Up   1
and so on..
8 : hint
In the hint i used "Warnsdorff's algorithm" to solve the problem. according to the algorithm you have to move knight to a legal square with minimum value specified in the table.
##############################################################################
#include <stdio.h>
void placeKnight(int position[],int board[][8][3]);
int moveKinght(int moveTo,int currentPosition[],int board[][8][3]);
void printBoard(int board[][8][3],int selection);
void heuristic(int board[][8][3]);
int isLegal(int moveTo,int currentPosition[],int board[][8][3]);
int main(){
int board[8][8][3]={0};
int currentPosition[2]={0,0};
heuristic(board);
placeKnight(currentPosition,board);
printBoard(board,0);
int input=0;
while(input>=0){
scanf("%d",&input);
if(input>=0&&input<8){
moveKnight(input,currentPosition,board);
heuristic(board);
printBoard(board,1);
}else if(input==8){
int selection=0;
printf("enter the selection :\n 0---> find legal moves\n 1---> find path you traveled\n 2--> hint\n");
scanf("%d",&selection);
if(selection>=0&&selection<=2){
printBoard(board,selection);
}else{
printf("invalied selection\n");
}
}
}
return 0;
}
void heuristic(int board[][8][3]){
int i;
int j;
int count=0;
int tempPosition[2];
for(i=0;i<8;i++){
for(j=0;j<8;j++){
tempPosition[0]=j;
tempPosition[1]=i;
int move;
for(move=0;move<8;move++){
count+=isLegal(move,tempPosition,board);
if(isLegal(move,tempPosition,board)==0){
//printf("%d , %d , moveto : %d\n",tempPosition[1],tempPosition[0],move);
}
}
board[i][j][2]=count;
count=0;
}
}
}
void printBoard(int board[][8][3],int selection){
int i;
int j;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
printf(" %2d",board[i][j][selection]);
}
printf("\n");
}
}
void placeKnight(int position[],int board[][8][3]){
int i;
int j;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
board[i][j][0]=0;
board[i][j][1]=0;
}
}
board[position[1]][position[0]][0]=1;
board[position[1]][position[0]][1]=1;
printf("The knight is initialized at ROW=%d   COLUMN=%d\n",position[1],position[0]);
}
int isLegal(int moveTo,int currentPosition[],int board[][8][3]){
int i;
int horizontal[8]={2,1,-1,-2,-2,-1,1,2};
int vertical[8]={-1,-2,-2,-1,1,2,2,1};
int count=board[currentPosition[1]][currentPosition[0]][1];
if((currentPosition[0]+horizontal[moveTo])<8&&
(currentPosition[0]+horizontal[moveTo])>=0&&
(currentPosition[1]+vertical[moveTo])<8&&
(currentPosition[1]+vertical[moveTo])>=0&&
board[currentPosition[1]+vertical[moveTo]][currentPosition[0]+horizontal[moveTo]][0]==0){
return 1;
}
else {
return 0;
}
}
int moveKnight(int moveTo,int currentPosition[],int board[][8][3]){
int i;
int horizontal[8]={2,1,-1,-2,-2,-1,1,2};
int vertical[8]={-1,-2,-2,-1,1,2,2,1};
int count=board[currentPosition[1]][currentPosition[0]][1];
if(isLegal(moveTo,currentPosition,board)){
currentPosition[0]+=horizontal[moveTo];
currentPosition[1]+=vertical[moveTo];
board[currentPosition[1]][currentPosition[0]][0]++;
board[currentPosition[1]][currentPosition[0]][1]=count+1;
}
else {
printf("the move is illegal\n");
}
}

Sunday, March 6, 2011

Bubble Sort

It is the simplest sorting technique with low memory consumption and low performance compared to other sorting techniques.


here we just compare adjacent elements and swap if there not in order.
after first iteration the last element is correctly placed. iterate the same until everything sorted.


####################################################

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define SIZE 10


void bubbleSort(int * const data);

int main(int argc, char** argv) {

    int data[SIZE];

    int i;
    srand(time(NULL));

    for(i=0;i<SIZE;i++){
        data[i]=rand()%100+1;
        printf("%d\n",data[i]);
    }

    bubbleSort(data);

    printf("\n\n\n");
    for(i=0;i<SIZE;i++){
        printf("%d\n",data[i]);
    }
    return (EXIT_SUCCESS);
}


void bubbleSort(int * const data){

    void swap(int * const swap1,int * const swap2);

    int i;
    for(i=0;i<SIZE;i++){
        int j;
        for(j=0;j<SIZE-i-1;j++){
            if(data[j]>data[j+1]){
                swap(&data[j],&data[j+1]);
            }
        }
    }
}


void swap(int * const swap1,  int * const swap2){
    int  tmp=*swap1;
    *swap1=*swap2;
    *swap2=tmp;
}

Selection Sort

SELECTION SORT.  (Recursive)
1.Selection Sort search array and looking for the smallest element in the array and swap it with the first element.
2.Again Search balance array without using the first element. (recursive part)


######################################################################
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 20
void printArray(int data[]){
int i;
printf("\n\n");
for(i=0;i<SIZE;i++){
printf("%d \n",data[i]);
}
}
void selectionSort(int data[],int start);
int main(int argc, char** argv) {
int data[SIZE];
//fill the array with random data
srand(time(NULL));
int i;
for(i=0;i<SIZE;i++){
data[i]=rand()%(1000);
}
printf("before Sort");
printArray(data);
//sort Array
selectionSort(data,0);
printf("after Sort");
printArray(data);
return (EXIT_SUCCESS);
}
void selectionSort(int data[],int start){
int i;
int temp=start;
for(i=start;i<SIZE;i++){
if(data[temp]>data[i]){
temp=i;
}
}
int value=data[temp];
data[temp]=data[start];
data[start]=value;
//recursive
if(start<=SIZE){
selectionSort(data,(start+1));
}
}

Sunday, February 27, 2011

Sieve of Eratosthenes

The Sieve of Eratosthenes is a method of finding prime numbers.
Basic steps in Algorithm.
1.Create an array with all elements initialized to 1. Array elements with prime subscripts will remain 1. others will eventually become 0.
2. Start from subscript 2, every time an array element is found with value 1, loop through the remainder of the array and set to 0 whose subscript is multiple of subscript which already found value with 1.
3. it is enough to find subscript with value 1 until sqrt(ARRAY_SIZE).
to know more about this method click here........
#################################################################
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 1000
/*
*
*/
int main(int argc, char** argv) {
int prime[SIZE]={0};
int i;
for(i=0;i<SIZE;i++){
prime[i]=1;
}
for(i=2;i<sqrt(SIZE);i++){
int j;
if(prime[i]==1){
for(j=i+1;j<SIZE;j++){
if((j%i)==0){
prime[j]=0;
}
}
}
}
for(i=0;i<SIZE;i++){
if(prime[i]==1){
printf("%d\n",i);
}
}
return (EXIT_SUCCESS);
}

Wednesday, February 23, 2011

Hello World

Hi This post is for testing my blog.
Still No plans on my mind on what to upload ;)