Thursday, July 29, 2010

Decimal To Roman Conversion

Decimal To Roman Conversion

/* Program in C for Decimal to Roman Number conversion */

#include< stdio.h>

main()
{
int a,b,c,d,e;
clrscr();
printf("Input a number (between 1-3000):");
scanf("%d",&e);
while (e==0||e>3000)
{
printf ("ERROR: Invalid Input!
");
printf ("Enter the number again:");
scanf ("%d",&e);
}
if (e>3000)
printf("Invalid");
a = (e/1000)*1000;
b = ((e/100)%10)*100;
c = ((e/10)%10)*10;
d = ((e/1)%10)*1;

if (a ==1000)
printf("M");
else if (a ==2000)
printf("MM");
else if (a ==3000)
printf("MMM");

if (b == 100)
printf("C");
else if (b == 200)
printf("CC");
else if (b == 300)
printf("CCC");
else if (b == 400)
printf("CD");
else if (b ==500)
printf("D");
else if (b == 600)
printf("DC");
else if (b == 700)
printf("DCC");
else if (b ==800)
printf("DCCC");
else if (b == 900)
printf("CM");


if (c == 10)
printf("X");
else if (c == 20)
printf("XX");
else if (c == 30)
printf("XXX");
else if (c == 40)
printf("XL");
else if (c ==50)
printf("L");
else if (c == 60)
printf("LX");
else if (c == 70)
printf("LXX");
else if (c ==80)
printf("LXXX");
else if (c == 90)
printf("XC");

if (d == 1)
printf("I");
else if (d == 2)
printf("II");
else if (d == 3)
printf("III");
else if (d == 4)
printf("IV");
else if (d ==5)
printf("V");
else if (d == 6)
printf("VI");
else if (d == 7)
printf("VII");
else if (d ==8)
printf("VIII");
else if (d == 9)
printf("IX");
getch();
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Program In C Language for Circle Through Three Points

Circle Through Three Points
Program In C Language for Circle Through Three Points

#include < stdio.h>
#include < math.h>
#include < conio.h>

int main()
{
clrscr();
double f,g,m,x1,x2,x3,y1,y2,y3;
double c,d,h,e,k,r,s;
for(;;)
{
if(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)==EOF)
//checking for input
break;

f = x3*x3-x3*x2-x1*x3+x1*x2+y3*y3-y3*y2-y1*y3+y1*y2; //formula
g = x3*y1-x3*y2+x1*y2-x1*y3+x2*y3-x2*y1;

if(g==0)
m = 0;
else
m = (f/g);

c = (m*y2)-x2-x1-(m*y1); //formula
d = (m*x1)-y1-y2-(x2*m);
e = (x1*x2)+(y1*y2)-(m*x1*y2)+(m*x2*y1);

h = (c/2); //formula
k = (d/2);
s = (((h)*(h))+((k)*(k))-e);
r = pow(s,.5);

printf("(x");

if(h>=0)
printf(" + ");
else if(h< 0)
printf(" - ");
if(h< 0)
h=-h;
printf("%.3lf)^2",(h));
printf(" + ");
printf("(y");
if(k>=0)
printf(" + ");
else if(k< 0)
printf(" - ");
if(k< 0)
k=-k;
printf("%.3lf)^2 = %.3lf^2",(k),r);

printf("");

printf("x^2 + y^2");

if(c>=0) printf(" + ");
else if(c< 0) printf(" - ");

if(c< 0) c=-c;
printf("%.3lfx",c);

if(d>=0) printf(" + ");
else if(d< 0) printf(" - ");

if(d< 0) d=-d;
printf("%.3lfy",d);

if(e>=0) printf(" + ");
else if(e< 0) printf(" - ");

if(e< 0) e=-e;
printf("%.3lf = 0",e);
printf("");
}

getch();
return 0;
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Radix Sort Algorithm

Radix Sort Algorithm

/* C program to sort an array using radix sort LINKED LIST implementation*/

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

void radix(int a[],int n,int m)
{
typedef struct node
{
int data;
struct node * next;
}NODE;

NODE * ptr,*start,*prev;
NODE *front[10], *rear[10];
int k=1,i,j,y,p;;
/*creating initial linked list*/
start=NULL;
for(i=0;i< n;++i)
{
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=a[i];
ptr->next=NULL;
if(start==NULL)
start=ptr;
else
prev->next=ptr;
prev=ptr;
}

/*radix sort*/

for(i=1;i< =m;++i)
{
for(j=0;j< 10;++j)
front[j]=NULL;
/*placing elements into queues*/
ptr=start;
while(ptr!=NULL)
{y=ptr->data/k %10;/*y is the digit*/
if(front[y]==NULL)
{
front[y]=ptr;
rear[y]=ptr;
}
else
{
rear[y]->next=ptr;
rear[y]=ptr;
}

ptr=ptr->next;
}

start=NULL;
for(j=0;j< 10;++j)
if(front[j]!=NULL)
{
if(start==NULL)
start=front[j];
else rear[p]->next=front[j];
p=j;
}
rear[p]->next=NULL;
k=k*10;
}
/*copying back to array*/
ptr=start;
for(i=0;i< n;++i,ptr=ptr->next)
a[i]=ptr->data;

}

void main()
{
int a[100],n,i,m;
char temp;
do
{
clrscr();
printf("===========================RADIX SORT===========================================\n");
printf("ENTER NUMBER OF NUMBERS AND NUMBER OF DIGITS\n");
scanf("%d%d",&n,&m);
printf("ENTER ELEMENTS\n");
for(i=0;i< n;++i)
scanf("%d",&a[i]);
radix(a,n,m);
printf("SORTED LIST\n");
for(i=0;i< n;++i)
printf("%d ",a[i]);
printf("\nDO YOU wish to continue?[y/n]\n");
scanf("%c",&temp);


}while(temp=='y'|| temp=='Y');
printf("\n---------------------------------------------------------------------------------\n");
getch();
}
/*OUTPUT:
===========================RADIX SORT===========================================

Enter number of numbers and number of digits
4
2
enter elements
25
65
35
45
sorted list
25 35 45 65
Do you wish to continue?[y/n]
n
--------------------------------------------------------------------------------*/  

--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Krushkal's Algorithm - 1 and 2

Krushkal's Algorithm - 2
/* C Program on Krushkal's Algorithm */

#include< stdio.h>
#include< stdlib.h>
void main()
{
int graph[15][15],s[15],pathestimate[15],mark[15];
int num_of_vertices,source,i,j,u,predecessor[15];
int count=0;
int minimum(int a[],int m[],int k);
void printpath(int,int,int[]);
printf("\nEnter The No. Of Vertices\n");
m scanf("%d",&num_of_vertices);
if(num_of_vertices< =0)
{
printf("\nThis Is Meaningless\n");
exit(1);
}
printf("\nEnter The Adjacent Matrix\n");
for(i=1;i< =num_of_vertices;i++)
{
printf("\nEnter The Elements Of Row %d\n",i);
for(j=1;j< =num_of_vertices;j++)
scanf("%d",&graph[i][j]);
}
printf("\nEnter The Source Vertex\n");
scanf("%d",&source);
for(j=1;j< =num_of_vertices;j++)
{
mark[j] = 0;
pathestimate[j] = 999;
predecessor[j] = 0;
}
pathestimate[source]=0;

while(count< num_of_vertices)
{
u = minimum(pathestimate,mark,num_of_vertices);
s[++count] = u;
mark[u] = 1;
for(i=1;i< =num_of_vertices;i++)
{
if(graph[u][i]>0)
{
if(mark[i]!=1)
{
if(pathestimate[i]>pathestimate[u]+graph[u][i])
{
pathestimate[i] = pathestimate[u]+graph[u][i];
predecessor[i] = u;
}
}
}
}
}
for(i=1;i< =num_of_vertices;i++)
{
printpath(source,i,predecessor);
if(pathestimate[i]!=999)
printf("->(%d)\n",pathestimate[i]);
}
}

int minimum(int a[],int m[],int k)
{
int mi=999;
int i,t;
for(i=1;i< =k;i++)
{
if(m[i]!=1)
{
if(mi>=a[i])
{
mi = a[i];
t = i;
}
}
}
return t;
}

void printpath(int x,int i,int p[])
{
printf("\n");
if(i==x)
printf("%d",x);
else if(p[i]==0)
printf("Number Path From %d To %d",x,i);
else
{
printpath(x,p[i],p);
printf("..%d",i);
}
}
/****************

Enter The No. Of Vertices
6

Enter The Adjacent Matrix

Enter The Elements Of Row 1
0 1 1 1 0 0

Enter The Elements Of Row 2
0 0 1 0 1 0

Enter The Elements Of Row 3
0 0 0 1 1 1

Enter The Elements Of Row 4
0 0 0 0 0 1

Enter The Elements Of Row 5
0 0 0 0 0 1

Enter The Elements Of Row 6
0 0 0 0 0 0

Enter The Source Vertex
1

1->(0)


1..2->(1)


1..3->(1)


1..4->(1)



1..3..5->(2)



1..4..6->(2)

*/

Krushkal's Algorithm
/* C Program On Krushkal's Algorithm */

#include < stdio.h>
#include < conio.h>
typedef struct
{
int node1;
int node2;
int wt;
}edge;

void sortedges(edge a[],int n)
{
int i,j;
edge temp;
for(i=0;i< n-1;++i)
for(j=i+1;j< n;++j)
if(a[i].wt>a[j].wt){temp=a[i];a[i]=a[j];a[j]=temp;}
}

int checkcycle(int p[],int i,int j)
{
int v1,v2;
v1 = i;
v2 = j;
while(p[i]>-1)
i = p[i];
while(p[j]>-1)
j = p[j];
if(i!=j)
{
p[j]=i;
printf("%d %d\n",v1,v2);
return 1;
}
return 0;
}
void main()
{
edge e[100];
int parent[100];
int n,i,j,m,k = 1,cost = 0;
clrscr();
printf("KRUSKAL's ALGORITHM\n");
printf("Enter number of nodes\n");
scanf("%d",&n);
for(i=0;i< n;++i)
parent[i]=-1;
i = 0;
printf("Enter number of edges\n");
scanf("%d",&m);
for(i=0;i< m;++i)
{
printf("enter an edge and wt\n");
scanf("%d %d %d", &e[i].node1,&e[i].node2,&e[i].wt);
}
sortedges(e,m);
printf("\n\nEdges of the tree\n");
i = 0;
while(k< n)
{
if(checkcycle(parent,e[i].node1,e[i].node2))
{
k++;
cost=cost+e[i].wt;
i++;
}
}
printf("cost = %d",cost);
getch();
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Heap Sort

 Heap Sort

/************* C Program To Sort An Array Using Heap Sort *************/

#include < stdio.h>
#include < conio.h>

void swap(int *x,int *y)
{
int temp;
temp=*x;
*x = *y;
*y = temp;
}

void heapsort(int a[],int n)
{
int i,s,f;
for(i=1;i< n;++i)
{
s=i;
f=(s-1)/2;
while( a[f]< a[s])
{
swap(&a[f],&a[s]);
s=f;
if(s==0)
break;
f=(s-1)/2;
}
}
for(i=n-1;i>=1;--i)
{
swap(&a[0],&a[i]);
f=0;
s=1;
if(i==1)
break;
if(i>2)if(a[2]>a[1])s=2;
while( a[f]< a[s] )
{
swap(&a[f],&a[s]);
f=s;
s=2*f+1;
if(i>s+1 )if(a[s+1]>a[s])s=s+1;
if (s>=i)
break;
}
}
}


void main()
{
int a[100],n,i;
clrscr();
printf("\t\tHEAP SORT\n");
printf("\nEnter The Number Of Elements\t: ");
scanf("%d",&n);
printf("\nEnter Elements\n");
for(i=0;i< n;++i)
scanf("%d",&a[i]);
heapsort(a,n);
printf("\n\t\t\tSorted List\n");
for(i=0;i< n;++i)
printf("\t%d",a[i]);
getche();
}
/***************** OUTPUT ******************
HEAP SORT

Enter The Number Of Elements : 6

Enter Elements
45
12
3
1
78
6

Sorted List
1 3 6 12 45 78
*/


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Binary Search Tree


Binary Search Tree

/* C Program on binary Search Tree */

#include< stdio.h>
#include< conio.h>
#include< string.h>
#include< dos.h>
#include< stdlib.h>

struct node
{
char data[15];
struct node *left,*right;
};

void insert(struct node *r,struct node *p)
{
if((r->right==NULL)&&(strcmp(p->data,r->data)>0))
r->right=p;
else if((r->right!=NULL)&&(strcmp(p->data,r->data)>0))
insert(r->right,p);
if((r->left==NULL)&&(strcmp(p->data,r->data)< 0))
r->left=p;
else if((r->left!=NULL)&&(strcmp(p->data,r->data)< 0))
insert(r->left,p);

}

void tree(struct node *r,int c)
{
int top,flag;
struct node *w,*stack[20];
if(r!=NULL)
{
if(c!=4)
{
if(c == 1)
printf(" %s ",r->data);
tree(r->left,c);
if(c == 2)
printf(" %s ",r->data);
tree(r->right,c);
if(c == 3)
printf(" %s ",r->data);
}
}
if(c == 4)
{
top = 0;
w = r;
flag = 0;
while((top != -1)&&(w!=NULL))
{
while((flag == 0) && (w->left!=NULL))
{
stack[top] = w;
top++;
w = w->left;
}
printf(" %s ",w->data);
if(w->right != NULL)
{
w = w->right;
flag = 0;
}
else
{
top--;
w = stack[top];
flag = 1;
}
}
}
}
void main()
{
int choice,c,i,flag;
char temp='N',temp1[15];
struct node *s,*root,*r,*q;
root = NULL;
do
{
clrscr();
printf("\n 1. Enter");
printf("\n 2. Delete ");
printf("\n 3. Search ");
printf("\n 4. Display");
printf("\n 5. Exit");
printf("\nEnter Your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("***** Data Entry ***** ");
do
{
s=malloc(sizeof(struct node));
s->left=NULL;
s->right=NULL;
printf("\nEnter Data : ");
scanf("%s",&s->data);
if(root==NULL)
root=s;
else
insert(root,s);
printf("\nEnter Your Elements[y/n] : ");
scanf("%c",&temp);
}
while(temp=='y');
break;

case 2:printf("****** Delete Operation *******\n");
do
{
printf("\nEnter Element To Be Deleted : ");
scanf("%s",temp1);
s=root;i=0;flag=0;
do
{
if(strcmp(s->data,temp1)>0)
{
r=s;
s=s->left;
i=2;
}
if(strcmp(s->data,temp1)==0)
{
flag=1;
if(i==0)
{
if(root->right!=NULL)
{
q=root->left;
root=root->right;
insert(root,q);
}
if(root->right==NULL)
root=root->left;
}
else
{
if(i==1)
{
q=s->left;
r->right=s->right;
if(s->left!=NULL)
insert(r,q);
}
if(i==2)
{
q=s->right;
r->left=s->left;
if(s->right!=NULL)
insert(r,q);
}
}
}
}
while(flag==0&&s!=NULL);
printf("\n Delete Any More[Y/N] : ");
scanf("%c",&temp);
}
while(temp=='y');
break;
case 3:printf("****** Search Operation *******\n");
do
{
printf("\n Enter Name To Be Searched");
scanf("%s",temp1);
i=0;
s=root;
while(s!=NULL&&i==0)
{
if(strcmp(s->data,temp1)< 0)
s=s->right;
if(strcmp(s->data,temp1)>0)
s=s->left;
if(strcmp(s->data,temp1)==0)
i=1;
}
if(i==0)
printf("\nElement Not Found\n");
else
printf("\nElement Found\n");
printf("\nEnter More Elements[Y/N] : ");
scanf("%c",&temp);
}
while(temp=='y');
break;
case 4:clrscr();
do
{
clrscr();
printf("\n 1. Preorder\n 2. Inorder \n 3. Postorder \n 4. Non Recursion \n 5. Exit");
printf("\nEnter Your Choice : ");
scanf("%d",&c);
if(root==NULL)
printf("Tree Not Started Yet");
else
tree(root,c);
printf("\n Press Any Key To Continue......");
getch();
}
while(c!=5);
break;
}
}
while(choice!=5);
}
/****************** OUTPUT ****************

1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 1
/****** Data Entry *******

Enter Data : Lionel
Enter More Elements(Y/N) : y
Enter Data : Dylan
Enter More Elements(Y/N) : y
Enter Data : Daniel
Enter More Elements(Y/N) : y
Enter Data : Malcolm
Enter More Elements(Y/N) : y
Enter Data : Cyril
Enter More Elements(Y/N) : y
Enter Data : Jason
Enter More Elements(Y/N) : n

1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 4

1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 1
Lionel Dylan Malcolm Cyril Daniel Jason

Press Any Key to Contiue....

1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 2
Malcolm Cyril Dylan Lionel Jason Daniel

Press Any Key to Contiue....

1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 3
Cyril Malcolm Dylan Lionel Jason Daniel

Press Any Key to Contiue....

1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 4
Malcolm Cyril Dylan Lionel Jason Daniel


Press Any Key to Contiue....

1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 5

Press Any Key To Continue.....

1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 3

Enter Name To Be Searched : Dylan
Element Found

Enter More Elements(Y/N) : n

1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 2

****** Delete Operation *******
Enter Element To Be Deleted : Dylan
Delete Any More(Y/n) : n

1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 5

*/


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Bubble Sort

Bubble Sort

/**** C Program For Implementation Of Bubble Sort. Sorting names entered by the user *****/
#include< stdio.h>
#include< conio.h>
#define MAX 10

char name[MAX][15];
void sort(int n)
{
int pa,cp,i,j,k,kk=0;
char temp[15];
pa=n-1;
cp=n-1;
for(i=1;i< =pa;i++)
{
for(j=1;j< =cp;j++)
{
kk=kk+1;
if(strcmp(name[j],name[j+1])>0)
{
strcpy(temp,name[j]);
strcpy(name[j],name[j+1]);
strcpy(name[j+1],temp);
}
}
printf("\n List after %d pass is ",i);
for(k=1;k< =n;k++)
printf("\n\t\t %s",name[k]);
getch();
}
clrscr();
printf("\n\t\t Total Comparisions Done : %d",kk);
}

void main()
{
int n,i,j;
clrscr();
printf("Enter How Many Names : ");
scanf("%d",&n);
if(n>MAX)
printf("\n\t\tArray Size IS Only %d",MAX);
else
{
printf("\n\t\tEnter %d Names :\n",n);
for(i=1;i< =n;i++)
{
printf("\t\t");
scanf("%s",name[i]);
}
sort(n);
printf("\n\n\t\tSorted List ");
for(i=1;i< =n;i++)
printf("\n\t\t%s",name[i]);
}
getch();
}
/********************* OUTPUT *******************
Enter How Many Names : 4

Enter 4 Names :
Malcolm
Lionel
Mayank
Pinto

List after 1 pass is
Lionel
Malcolm
Mayank
Pinto
List after 2 pass is
Lionel
Malcolm
Mayank
Pinto
List after 3 pass is
Lionel
Malcolm
Mayank
Pinto

*/


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

LCM and HCM of two numbers


LCM and HCM of two numbers

/* C++ program to calculate LCM and HCM of two numbers */
#include< stdio.h>
#include< conio.h>
void main()
{
int a,b,c;
cout< < "Enter two nos : ;
cin>>a>>b;
c=a*b;
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
cout< < "HCM \t= " < < a;
cout< < "LCM \t= " < < c/a;
getch();
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

DIJKSRTRA'S ALGORITHM


DIJKSRTRA'S ALGORITHM
/*Implementation of Shortest Path Algorithm(DIJKSRTRA's ALGORITHM) in C*/

#include< stdio.h>
#include< conio.h>
#include< process.h>
#include< string.h>
#include< math.h>
#define IN 99
#define N 6

int dijkstra(int cost[][N], int source, int target);

void main()
{
int cost[N][N],i,j,w,ch,co;
int source, target,x,y;
clrscr();
printf("\tShortest Path Algorithm(DIJKSRTRA's ALGORITHM\n\n");
for(i=1;i< N;i++)
for(j=1;j< N;j++)
cost[i][j] = IN;
for(x=1;x< N;x++)
{
for(y=x+1;y< N;y++)
{
printf("Enter the weight of the path between node %d and %d: ",x,y);
scanf("%d",&w);
cost [x][y] = cost[y][x] = w;
}
printf("\n");
}
printf("\nEnter The Source:");
scanf("%d", &source);
printf("\nEnter The target");
scanf("%d", &target);
co = dijsktra(cost,source,target);
printf("\nShortest Path: %d",co);
getch();
}

int dijsktra(int cost[][N],int source,int target)
{
int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j;
char path[N];
for(i=1;i< N;i++)
{
dist[i] = IN;
prev[i] = -1;
}
start = source;
selected[start]=1;
dist[start] = 0;
while(selected[target] ==0)
{
min = IN;
m = 0;
for(i=1;i< N;i++)
{
d = dist[start] +cost[start][i];
if(d< dist[i]&&selected[i]==0)
{
dist[i] = d;
prev[i] = start;
}
if(min>dist[i] && selected[i]==0)
{
min = dist[i];
m = i;
}
}
start = m;
selected[start] = 1;
}
start = target;
j = 0;
while(start != -1)
{
path[j++] = start+65;
start = prev[start];
}
path[j]='\0';
strrev(path);
printf("%s", path);
return dist[target];
}
/***** Output *********

Shortest Path Algorithm(DIJKSRTRA's ALGORITHM

Enter the weight of the path between node 1 and 2: 2
Enter the weight of the path between node 1 and 3: 3
Enter the weight of the path between node 1 and 4: 4
Enter the weight of the path between node 1 and 5: 5

Enter the weight of the path between node 2 and 3: 5
Enter the weight of the path between node 2 and 4: 2
Enter the weight of the path between node 2 and 5: 3

Enter the weight of the path between node 3 and 4: 1
Enter the weight of the path between node 3 and 5: 4

Enter the weight of the path between node 4 and 5: 5



Enter The Source:2

Enter The target4
CE
Shortest Path: 2
*/

--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

PC to PC Communication using RS-232


PC to PC Communication using RS-232
/*Aim: PC to PC Communication using RS-232 in 'C'. */

#include
#include
#define COM1 0
#define DATA_READY 0x100
#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
int main(void)
{
int in, out, status;
bioscom(0, SETTINGS, COM1); /*initialize the port*/
cprintf("Data sent to you: ");
while (1)
{
status = bioscom(3, 0, COM1); /*wait until get a data*/
if (status & DATA_READY)
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) /*input a data*/
putch(out);
if (kbhit())
{
if ((in = getch()) == 27) /* ASCII of Esc*/
break;
bioscom(1, in, COM1); /*output a data*/
}
}
return 0;
}

/* OUTPUT:-
Data sent to you: HI...how are you??
*/

--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

ISO - OSI Model

ISO - OSI Model

/* Draw ISO - OSI Model using C */

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

void main()
{
int driver, mode;
int i,j;
driver = DETECT;
initgraph(&driver,&mode,"");

outtextxy(250,450,"ISO OSI Model");
delay(2000);
outtextxy(90,30,"Sender");
delay(500);
setcolor(6);
for(i=50;i< =350;i+=50)
{
rectangle(200,i,50,i+30);
delay(500);
}
setcolor(10);
outtextxy(70,60,"Application")
;
delay(500);
outtextxy(70,110,"Presentation");
delay(500);
outtextxy(70,160,"Session");
delay(500);
outtextxy(70,210,"Transport");
delay(500);
outtextxy(70,260,"Network");
delay(500);
outtextxy(70,310,"Data Link");
delay(500);
outtextxy(70,360,"Physical");
delay(500);
setcolor(15);
outtextxy(390,30,"Receiver");
delay(500);
setcolor(6);
for(i=50;i< =350;i+=50)
{
rectangle(350,i,500,i+30);
delay(500);
}
setcolor(10);
outtextxy(370,60,"Application");
delay(500);
outtextxy(370,110,"Presentation");
delay(500);
outtextxy(370,160,"Session");
delay(500);
outtextxy(370,210,"Transport");
delay(500);
outtextxy(370,260,"Network");
delay(500);
outtextxy(370,310,"Data Link");
delay(500);
outtextxy(370,360,"Physical");
delay(500);
// sender Lines
line(120,80,120,100);
delay(500);
line(120,130,120,150);
delay(500);
line(120,180,120,200);
delay(500);
line(120,230,120,250);
delay(500);
line(120,280,120,300);
delay(500);
line(120,330,120,350);
delay(500);
line(120,380,120,400);
delay(500);
// Physical Connection
line(120,400,420,400);
// Receiver Lines
line(420,380,420,400);
delay(500);
line(420,330,420,350);
delay(500);
line(420,280,420,300);
delay(500);
line(420,230,420,250);
delay(500);
line(420,180,420,200);
delay(500);
line(420,130,420,150);
delay(500);
line(420,80,420,100);
//virtual connection
setcolor(15);
delay(500);
outtextxy(210,35,"Virtual Connection");
delay(1000);
for(j=65;j< =365;j+=50)
{
for(i=0;i< 15;i++)
{
setcolor(i);
line(200,j,230,j);
delay(10);
line(235,j,265,j);
delay(10);
line(270,j,300,j);
delay(10);
line(305,j,335,j);
delay(10);
line(340,j,350,j);
delay(10);
}
}
delay(500);
}
/*

*/


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Two Dimentional array in C

Two Dimentional array in C

/* C program to input and display a 2-d array*/

#include< stdio.h>
#include< conio.h>
void main()
{
int num[3][3],i,j;
clrscr();
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
scanf("%d",&num[i][j]);
}
}
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
printf("\n%d",num[i][j]);
}
printf("\n");
}
getch();
}

Pointers example

Pointers example

/* Example of pointers in C. Thsi program uses a function to modify a string using pointers */

#include< stdio.h>
#include< conio.h>
void main()
{
void getstr(char *ptr_str,int *ptr_int);
int var=5;
char *pstr="lionel";
clrscr();
getstr(pstr,&var);
printf("The value of var after modification using pointer in a function is %d,var");
}
void getstr (char *ptr_str,int *ptr_int)
{
printf("%s\n",ptr_str);
*ptr_int=6;
getch();
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Call By Reference in C && Call by Values in C

Call By Reference program in C
/* Program for inerchanging two numbers demonstrating Call By Reference in C */

#include<>
#include<>

void swap(int *,int *);

void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(&x,&y);
//printf("\n%x %x",&x,&y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}

void swap(int *u,int *v)
{
int temp;
temp=*u;
*u=*v;
*v=temp;

return;
}

Call by Values in C
/* Program on interchanging two numbers demonstrating Call By Values in C*/
#include< stdio.h>
#include< conio.h>
void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(x,y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}
swap(int u,int v)
{
int temp;
temp=u;
u=v;
v=temp;
return;
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Diamond In C

 Diamond In C

/* C program to display a diamond using arrays */

#include< iostream.h>
#include< conio.h>
void main()
{
int i,j;
clrscr();
int no;
cout< < "Enter A Value";
cin>>no;
for(i=no;i>=1;i--)
{
cout< < endl;
for(int k=1;k< =i;k++)
cout< < " ";

for(j=i;j< =no;j++)
cout< < "*";

for(j=i;j< no;j++)
cout< < "*";
}
//SECOND PART

for(i=no;i>=1;i--)
{
cout< < endl;
cout< < " ";
for(int k=no;k>=i;k--)
cout<<" ";

for(j=i-1;j>=1;j--)
cout< < "*";

for(j=i-1;j>1;j--)
cout<<"*";

}
getch();
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

Two Pass Assembler && LEXICAL ANALIZER

Two Pass Assembler && LEXICAL ANALIZER

Two Pass Assembler
#include< stdio.h>
#include< conio.h>
#include< string.h>
#define lines_in_program 9
void print(char *p,int loc,int len,char ra)
{printf("%s\t%d\t%d\t%c\n",p,loc,len,ra);}
void main()
{
char *p[9][4] = {{"PRG1","START","",""},{"","USING","*","15"},
{"","L","1","FIVE"}, {"","A","1","FOUR"},
{"","ST","1","TEMP"}, {"FOUR","DC","F'4'",""},
{"FIVE","DC","F'5'",""}, {"TEMP","DS","1F",""},
{"","END","",""}};
int i,j=0,location_counter=0;
clrscr();
for (i=0;i< 9;i++)
{ for(j=0;j< 4;j++)
printf("%s\t",p[i][j]);
printf("\n");
}
printf("\n\n\n\n Symbol ");
printf("Table:\nSYMBOL\tVALUE\tLENGTH\tRelocatable/Absolute\n");
printf("---------------------------------------------\n");
for(i=0;i< 9;i++)
{ if(strcmp(p[i][1],"START")==0)
print(p[i][0],location_counter,1,'R');
else if(strcmp(p[i][0],"")!=0)
{
print(p[i][0],location_counter,4,'R');
location_counter=4+location_counter;
}
else if(strcmp(p[i][1],"USING")==0){}
else{location_counter=4+location_counter;}
}
getch();
}


/*OUTPUT:
PRG1 START
USING * 15
L 1 FIVE
A 1 FOUR
ST 1 TEMP
FOUR DC F'4'
FIVE DC F'5'
TEMP DS 1F
END

Symbol Table:
SYMBOL VALUE LENGTH Relocatable/Absolute
---------------------------------------------
PRG1 0 1 R
FOUR 12 4 R
FIVE 16 4 R
TEMP 20 4 R */

Two Pass Assembler
#include< stdio.h>
#include< string.h>
#include< conio.h>


void main()
{
char *code[9][4]={
{"PRG1","START","",""},
{"","USING","*","15"},
{"","L","",""},
{"","A","",""},
{"","ST","",""},
{"FOUR","DC","F",""},
{"FIVE","DC","F",""},
{"TEMP","DS","1F",""},
{"","END","",""}
};
char av[2],avail[15]={'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'};
int i,j,k,count[3],lc[9]={0,0,0,0,0,0,0,0,0},loc=0;
clrscr();
printf("----------------------------------------------------\n");
printf("LABEL\t\tOPCODE\n");
printf("----------------------------------------------------\n\n");
for(i=0;i< =8;i++)
{
for(j=0;j< =3;j++)
{
printf("%s\t\t",code[i][j]);
}
j=0;
printf("\n");
}
getch();
printf("-----------------------------------------------------");
printf("\nVALUES FOR LC : \n\n");
for(j=0;j< =8;j++)
{
if((strcmp(code[j][1],"START")!=0)&&(strcmp(code[j][1],"USING")!=0)&&(strcmp(code[j][1],"L")!=0))
lc[j]=lc[j-1]+4;
printf("%d\t",lc[j]);
}
printf("\n\nSYMBOL TABLE:\n----------------------------------------------------\n");
printf("SYMBOL\t\tVALUE\t\tLENGTH\t\tR/A");
printf("\n----------------------------------------------------\n");

for(i=0;i< 9;i++)
{
if(strcmp(code[i][1],"START")==0)
{
printf("%s\t\t%d\t\t%d\t\t%c\n",code[i][0],loc,4,'R');
}
else if(strcmp(code[i][0],"")!=0)
{
printf("%s\t\t%d\t\t%d\t\t%c\n",code[i][0],loc,4,'R');
loc=4+loc;
}
else if(strcmp(code[i][1],"USING")==0){}
else
{loc=4+loc;}
}
printf("----------------------------------------------------");

printf("\n\nBASE TABLE:\n-------------------------------------------------------\n");
printf("REG NO\t\tAVAILIBILITY\tCONTENTS OF BASE TABLE");
printf("\n-------------------------------------------------------\n");
for(j=0;j< =8;j++)
{
if(strcmp(code[j][1],"USING")!=0)
{}
else
{
strcpy(av,code[j][3]);
}
}
count[0]=(int)av[0]-48;
count[1]=(int)av[1]-48;
count[2]=count[0]*10+count[1];
avail[count[2]-1]='Y';

for(k=0;k< 16;k++)
{
printf(" %d\t\t %c\n",k,avail[k-1]);
}

printf("-------------------------------------------------------\n");
printf("Continue..??");
getchar();
printf("PASS2 TABLE:\n\n");
printf("LABEL\t\tOP1\t\tLC\t\t");
printf("\n----------------------------------------------------\n");
loc=0;
for(i=0;i< =8;i++)
{
for(j=0;j< =3;j++)
{
printf("%s\t\t",code[i][j]);
}
j=0;
printf("\n");
}
printf("-----------------------------------------------------");

getch();

}
/*
----------------------------------------------------
LABEL OPCODE
----------------------------------------------------

PRG1 START
USING * 15
L
A
ST
FOUR DC F
FIVE DC F
TEMP DS 1F
END



-----------------------------------------------------
VALUES FOR LC :

0 0 0 4 8 12 16 20 24

SYMBOL TABLE:
----------------------------------------------------
SYMBOL VALUE LENGTH R/A
----------------------------------------------------

PRG1 0 4 R
FOUR 12 4 R
FIVE 16 4 R
TEMP 20 4 R


----------------------------------------------------

BASE TABLE:
-------------------------------------------------------
REG NO AVAILIBILITY CONTENTS OF BASE TABLE
-------------------------------------------------------
0 -----------------------------------
1 N
2 N
3 N
4 N
5 N
6 N
7 N
8 N
9 N
10 N
11 N
12 N
13 N
14 N
15 Y

-------------------------------------------------------
Continue..??
PASS2 TABLE:

LABEL OP1 LC
----------------------------------------------------
PRG1 START
USING * 15
L
A
ST
FOUR DC F
FIVE DC F
TEMP DS 1F
END
-----------------------------------------------------


*/

Lexical Analizer
/* TO IMPLEMENT LEXICAL ANALIZER IN C */

#include< conio.h>
#include< string.h>

void main()
{
int i,j,lc;
char *a[9][4]={"PRG","START" ," " ," ",
" " ,"USING" ,"*" ,"15",
" ","L","1","FIVE",
" ","A","1","FOUR",
" ","ST","1","TEMP",
"FOUR ","DC","F","4",
"FIVE","DC","F","5",
"TEMP","DS","1","F",
" " ,"END"," "," ", };
clrscr();
printf("\n \t\t LEXICAL ANALIZER \n");

for(i=0;i< 9;i++)
{ for(j=0;j< 4;j++)
{ if(isalpha(*a[i][j]))
printf("\n STRING : %s",a[i][j]);
if(isdigit(*a[i][j]))
printf("\n DIGIT : %s",a[i][j]);
}
printf("\n");
}

getch();
}
/* OUTPUT:-

LEXICAL ANALIZER

STRING : PRG
STRING : START

STRING : USING
DIGIT : 15

STRING : L
DIGIT : 1
STRING : FIVE

STRING : A
DIGIT : 1
STRING : FOUR

STRING : ST
DIGIT : 1
STRING : TEMP

STRING : FOUR
STRING : DC
STRING : F
DIGIT : 4

STRING : FIVE
STRING : DC
STRING : F
DIGIT : 5

STRING : TEMP
STRING : DS
DIGIT : 1
STRING : F

STRING : END

*/





--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/