Tuesday 22 May 2012

c program of gauss ELIMINITION method


/*Gauss Elimination */
# include <stdio.h>
# include <conio.h>
# include <math.h>
# define MAX 10
void main()
{
int i,j,n,k;
float mat[MAX][MAX],x[MAX],temp,pivot,sum=0;
clrscr();
printf("\t\t\t GAUSS ELIMINITION METHOD\n");
printf("-------------------------------------------------------------------\n");
printf("Enter No of Equtions : ");
scanf("%d",&n);
printf("Enter Coefficients of Eqution \n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%f",&mat[i][j]);
printf("Enter Constant value\n");
for(i=1;i<=n;i++)
{
scanf("%f",&mat[i][n+1]);
x[i]=mat[i][n+1];
}
for(i=2;i<=n;i++)
{
for(j=i;j<=n;j++)
{
pivot=mat[j][i-1]/mat[i-1][i-1];
for(k=i-1;k<=n+1;k++)
mat[j][k]=mat[j][k]-pivot*mat[i-1][k];
}
}
printf("Eliminated matrix as :- \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf("\t%.2f",mat[i][j]);
printf("\n");
}
for(i=1;i<=n;i++)
{
if(mat[i][i]==0)
{
printf("Since diagonal element become zero\n Hence solution is not possible\n");
exit(1);
}
}
printf("Solution : \n");
for(i=0;i {
sum=0;
for(j=n;j>n-i;j--)
sum=sum+mat[n-i][j];

x[n-i]=(mat[n-i][n+1]-sum*x[n])/mat[n-i][n-i];
printf("X%d = %4.2f\n",n-i,x[n-i]);
}

getch();
}

OUTPUT :-


GAUSS ELIMINITION METHOD
------------------------------------------------------------------------------
Enter No of Equtions : 3
Enter Coefficients of Eqution
4 3 -2
1 1 1
3 -2 1
Enter Constant value
5 3 2
Eliminated matrix as :-
4.00 3.00 -2.00 5.00
0.00 0.25 1.50 1.75
0.00 0.00 28.00 28.00
Solution :
X3 = 1.00
X2 = 1.00
X1 = 1.00

facebook page of the blog

click here to see the facebook page of this blog.
click on LIKE................. :)

C Program Of NA Using Trapezoidal Interpolation


/*Trapezoidal rule */
# include <stdio.h>
# include <conio.h>
# define MAX 20
void main()
{
int i,j,n;
float x[MAX],y[MAX],sum=0,h,res;
clrscr();
printf("Solution using Trapezoidal rule \n");
printf("Enter Number of data points : ");
scanf("%d",&n);
printf("Enter value of table value set by set\n");
for(i=1;i<=n;i++)
{
printf("Enter value of x[%d] and y[%d] ",i,i);
scanf("%f%f",&x[i],&y[i]);
}
h=x[2]-x[1];
printf("\nInterval :=%f\n",h);
sum=y[1]+y[n];
for(i=2;i<n;i++)
sum=sum+y[i]*2;

res=sum*(h/2);
printf ("Integral from %3.2f to %3.2f is : = %f",x[1],x[n],res);
getch();
}
OUTPUT :-
Solution using Trapezoidal rule
Enter Number of data points : 6
Enter value of table value set by set
Enter value of x[1] and y[1] 7.47 1.93
Enter value of x[2] and y[2] 7.48 1.95
Enter value of x[3] and y[3] 7.49 1.98
Enter value of x[4] and y[4] 7.50 2.01
Enter value of x[5] and y[5] 7.51 2.03
Enter value of x[6] and y[6] 7.52 2.06

Interval :=0.010000
Integral from 7.47 to 7.52 is : = 0.099652

C Program Of NA Using Simpson 1/3 Rule


/*Simpson 1/3 Rule */
# include <stdio.h>
# include <conio.h>
# define MAX 20
void main()
{
int i,j,n;
float x[MAX],y[MAX],sum=0,h,res;
clrscr();
printf("Solution of 1/(1+x)dx using Simpson's 1/3 rule \n");
printf("Enter Number of data points : ");
scanf("%d",&n);
printf("Enter value of table value set by set\n");
for(i=1;i<=n;i++)
{
scanf("%f",&x[i]);
y[i]=1/(x[i]+1);
}
printf("X \t\t Y\n");
for(i=1;i<=n;i++)
printf("%f\t%f\n",x[i],y[i]);
h=x[2]-x[1];
printf("\nSegment Interval `h':=0.25\n");
sum=sum+y[1]+y[n];
for(i=2;i<n;i++)
{
if(i%2==0)
sum=sum+y[i]*4;
else
sum=sum+y[i]*2;
}
res=sum*(0.25/3);
printf ("Integral from %3.2f to %3.2f is : = %f",x[1],x[n],res);
getch();
}
OUTPUT
Solution of 1/(1+x)dx using Simpson's 1/3 rule
Enter Number of data points : 5
Enter value of table value for x column
0 .25 .50 .75 1
X Y
0.000000 1.000000
0.250000 0.800000
0.500000 0.666667
0.750000 0.571429
1.000000 0.500000

Segment Interval `h':=0.25
Integral from 0.00 to 1.00 is : = 0.693254

C Program Of NA Using Simpson 3/8 Rule


/*Simpson 3/8 rule */
# include <stdio.h>
# include <conio.h>
# define MAX 20
void main()
{
int j,n=0;
float x[MAX],y[MAX],sum=0,h,res,lb,ub,i;
clrscr();
printf("Solution of 1/(1+x)dx using Simpson's 3/8 rule \n");
printf ("Enter initial value : ");
scanf("%f",&lb);
printf("Enter final value : ");
scanf("%f",&ub);
printf("Enter no. of Subinterval : ");
scanf("%f",&h);
h=(ub-lb)/h;
for(i=lb;i<=ub;i=i+h)
{
x[n]=i;
y[n]=1/(1+x[n]);
n++;
}
printf("No.\t X\t\tY=1/(1+x)\n");
printf("---------------------------------------\n");
sum=y[0]+y[n-1];
for(j=0;j<n;j++)
printf("%d\t%f\t%f\n",j,x[j],y[j]);
printf("---------------------------------------\n");
for(j=1;j<n-1;j++)
{
if(j%3==0)
sum=sum+y[j]*2;
else
sum=sum+y[j]*3;
}
res=((3*h)/8)*sum;
printf("\nIntegral from %f to %f when h = %f is = %f",x[0],x[n-1],h,res);
getch();
}

OUTPUT

Solution of 1/(1+x)dx using Simpson's 3/8 rule
Enter initial value : 6
Enter final value : 15
Enter no. of Subinterval : 8
No. X Y=1/(1+x)
---------------------------------------
0 6.000000 0.142857
1 7.125000 0.123077
2 8.250000 0.108108
3 9.375000 0.096386
4 10.500000 0.086957
5 11.625000 0.079208
6 12.750000 0.072727
7 13.875000 0.067227
8 15.000000 0.062500
---------------------------------------

Integral from 6.000000 to 15.000000 when h = 1.125000 is = 0.817303

C Program Of NA Using Runga-Kutta Mthod Of 4th Order

/* Runge-kutta method of 4th order to solve 10*dy/dx=(x*x)+(y*y)*/
# include <stdio.h>
# include <conio.h>
void main()
{
int c=0;
float x,y0,xp,h,i,y1,m1,m2,m3,m4;
float f(float,float);
clrscr();
printf("Solution by Runge kutta 2nd order Method\n");
printf("Enter initial Boundry condition x,y : ");
scanf("%f%f",&x,&y0);
printf("Enter Value of X at which Y is required : ");
scanf("%f",&xp);
printf("Enter Interval ,h : ");
scanf("%f",&h);
printf(" No. X\t m1 \t m2\t m3 \t m4 \t Y\n");
printf("-------------------------------------------------------------------\n");
for(i=x;i<=xp;i=i+h)
{
c++;
m1=h*f(i,y0);
m2=h*f(i+(h/2),y0+(m1/2));
m3=h*f(i+(h/2),y0+(m2/2));
m4=h*f(i+h,y0+m3);
y1=y0+((m1+2*m2+2*m3+m4)/6);
printf("%2d %5.6f %5.6f %5.6f %5.6f %5.6f %5.6f\n",c,i,m1,m2,m3,m4,y1);
y0=y1;
}
getch();
}
float f(float x,float y)
{
return ((x*x)+(y*y))/10;
}



OUTPUT



Solution by Runge kutta 2nd order Method
Enter initial Boundry condition x,y : 0 1
Enter Value of X at which Y is required : .09


Enter Interval ,h : .03
No. X m1 m2 m3 m4 Y
-------------------------------------------------------------------------------
1 0.000000 0.003000 0.003010 0.003010 0.003021 1.003010
2 0.030000 0.003021 0.003033 0.003033 0.003047 1.006043
3 0.060000 0.003047 0.003062 0.003062 0.003079 1.009106
4 0.090000 0.003079 0.003097 0.003097 0.003117 1.012204

Monday 9 April 2012

Program in C to insert a node at the last position in a given doubly linked list.

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

#define null 0

void main()

{

struct dnode

{

struct dnode *prev;

int data;

struct dnode *next;

} *temp,*start,*end,*n;



int i;

char c;

clrscr();

start=end=null;

for(i=0;i<=1;i++)

{

if(start==null)

{

printf("enter data for the node:");

scanf("%d",&temp->data);

temp->next=null;

temp->prev=null;

start=temp;

end=temp;

}

else

{

while(1)

{

printf("are you want to add another node(y/Y):");

fflush(stdin);

scanf("%c",&c);

if(c=='y'||c=='Y')

{

n=(struct dnode*)malloc(sizeof(struct dnode));

printf("enter data for the node:");

scanf("%d",&n->data);

n->next=null;

n->prev=temp;

temp->next=n;

temp=n;

end=n;

}

else

break;

}

}

}



printf("the list you created is:\n");

temp=start;

while(temp->next!=null)

{

printf("%d\t",temp->data);

temp=temp->next;

}

printf("%d\n",temp->data);

printf("addition at last place\n");

{

n=(struct dnode *)malloc(sizeof(struct dnode));

printf("enter the data for the node:");

scanf("%d",&n->data);

n->prev=end;

n->next=null;

end->next=n;

end=n;

}

printf("after operation list is:\n");

temp=start;

while(temp->next!=null)

{

printf("%d\t",temp->data);

temp=temp->next;

}

printf("%d\n",temp->data);

getch();

}



OUTPUT:

Enter data for the node:45

Are you want to create another node(y/Y):Y



Enter data for the node:65

Are you want to create another node(y/Y):n

The list you created

45 65

Addition at the first place

Enter data for the node:22

After operation list is: 45 65 22

Program in C to insert a node at first position in a given doubly linked list.

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

#define null 0

void main()

{

struct dnode

{

struct dnode *prev;

int data;

struct dnode *next;

} *temp,*start,*end,*n;



int i;

char c;

clrscr();

start=end=null;

for(i=0;i<=1;i++)

{

if(start==null)

{

printf("enter data for the node:");

scanf("%d",&temp->data);

temp->next=null;

temp->prev=null;

start=temp;

end=temp;

}

else

{

while(1)

{

printf("are you want to add another node(y/Y):");

fflush(stdin);

scanf("%c",&c);

if(c=='y'||c=='Y')

{

n=(struct dnode*)malloc(sizeof(struct dnode));

printf("enter data for the node:");

scanf("%d",&n->data);

n->next=null;

n->prev=temp;

temp->next=n;

temp=n;

end=n;

}

else

break;

}

}

}



printf("the list you created is:\n");

temp=start;

while(temp->next!=null)

{

printf("%d\t",temp->data);

temp=temp->next;

}

printf("%d\n",temp->data);

printf("addition at first place\n");

{

n=(struct dnode *)malloc(sizeof(struct dnode));

printf("enter the data for the node:");

scanf("%d",&n->data);

n->prev=null;

n->next=start;

start->prev=n;

start=n;

}

printf("after operation list is:\n");

temp=start;

while(temp->next!=null)

{

printf("%d\t",temp->data);

temp=temp->next;

}

printf("%d\n",temp->data);

getch();

}



OUTPUT:

Enter data for the node:45

Are you want to create another node(y/Y):Y



Enter data for the node:65

Are you want to create another node(y/Y):n

The list you created

45 65

Addition at the first place

Enter data for the node:22

After operation list is: 22 45 65

Program in C to subtract two polynomials.

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#define NULL 0

void main()

{

struct poly

{

int coff;

int expo;

struct poly *link;

}*temp1,*start1,*temp2,*start2,*start3,*temp3;

int n,i,z=1,num;

char c;

clrscr();

start1=NULL;

printf("\tPOLYNOMIAL CREATION IN LINK LIST AND SUBTRACTION\n\n");

while(1)

{

if(start1==NULL)

{

temp1=(struct poly*)malloc(sizeof(struct poly));

printf("Enter Coefficient and Exponent for Node %d\n",z);

scanf("%d %d",&temp1->coff,&temp1->expo);

start1=temp1;

temp1->link=NULL;

}

else

{

temp1->link=(struct poly*)malloc(sizeof(struct poly));

temp1=temp1->link;

printf("Enter Coefficient and exponent for Node %d\n",z);

scanf("%d %d",&temp1->coff,&temp1->expo);

}

z++;

printf("Do you want to create another node\n");

fflush(stdin);

scanf("%c",&c);

if(c!='y')

{

temp1->link=NULL;

break;

}

}

start2=NULL;

temp2=NULL;

z=1;

while(1)

{

if(start2==NULL)

{

temp2=(struct poly*)malloc(sizeof(struct poly));

printf("Enter Coefficient and exponent for Node %d\n",z);

scanf("%d %d",&temp2->coff,&temp2->expo);

start2=temp2;

temp2->link=NULL;

}

else

{

temp2->link=(struct poly*)malloc(sizeof(struct poly));

temp2=temp2->link;

printf("Enter Coefficient and exponent for Node %d\n",z);

scanf("%d %d",&temp2->coff,&temp2->expo);

}

z++;

printf("Do you want to create another node\n");

fflush(stdin);

scanf("%c",&c);

if(c!='y')

{

temp2->link=NULL;

break;

}

}

// TARVERSING

temp1=NULL;

temp2=NULL;

temp1=start1;

temp2=start2;

printf("Traversal of Polynomial Linked List 1\n");

while(temp1!=NULL)

{

printf("%2dx^%d-",temp1->coff,temp1->expo);

temp1=temp1->link;

}

printf("\b \b");

printf("\nTraversal of Polynomial Linked List 2\n");

while(temp2!=NULL)

{

printf("%2dx^%d -",temp2->coff,temp2->expo);

temp2=temp2->link;

}

printf("\b \b");

// subtraction

temp1=NULL;

temp2=NULL;

temp1=start1;

temp2=start2;

temp3=NULL;

start3=NULL;

while(1)

{

if((temp1!=NULL)||(temp2!=NULL))

{

if(start3==NULL)

{

if((temp1->expo)==(temp2->expo))

{

temp3=(struct poly*)malloc(sizeof(struct poly));

temp3->coff= (temp1->coff) - (temp2->coff);

temp3->expo=temp1->expo;

start3=temp3;

temp1=temp1->link;

temp2=temp2->link;

temp3->link=NULL;

}

else if(temp1->expo>temp2->expo)

{

temp3=(struct poly*)malloc(sizeof(struct poly));

temp3->coff=temp1->coff;

temp3->expo=temp1->expo;

start3=temp3;

temp1=temp1->link;

temp3->link=NULL;

}

else

{

temp3=(struct poly*)malloc(sizeof(struct poly));

temp3->coff=temp2->coff;

temp3->expo=temp2->expo;

start3=temp3;

temp2=temp2->link;

temp3->link=NULL;

}

}

else

{

if(temp1->expo==temp2->expo)

{

temp3->link=(struct poly*)malloc(sizeof(struct poly));

temp3=temp3->link;

temp3->coff= (temp1->coff) - (temp2->coff);

temp3->expo=temp1->expo;

temp1=temp1->link;

temp2=temp2->link;

}

else if(temp1->expo>temp2->expo)

{

temp3->link=(struct poly*)malloc(sizeof(struct poly));

temp3=temp3->link;

temp3->coff=temp1->coff;

temp3->expo=temp1->expo;

temp1=temp1->link;

}

else

{

temp3->link=(struct poly*)malloc(sizeof(struct poly));

temp3=temp3->link;

temp3->coff=temp2->coff;

temp3->expo=temp2->expo;

temp2=temp2->link;

}

}

}

else

break;

}

temp3->link=NULL;

//traversing temp3

temp3=NULL;

temp3=start3;

printf("\nTraversal of Polynomial Linked List after subtracting Temp1 & Temp2\n");

while(temp3!=NULL)

{

printf("%2dx^%d - ",temp3->coff,temp3->expo);

temp3=temp3->link;

}

printf("\b\b");

printf("\nTHE END\n");

getch();

}



OUTPUT:

POLYNOMIAL CREATION IN LINK LIST AND SUBTRACTION



Enter Coefficient and exponent for Node 1

6

3

Do you want to create another node

Y

Enter Coefficient and exponent for Node 2

8

2

Do u want to create another node

N

Enter Coefficient and exponent for Node 1

7

3

Do you want to create another node

Y

Enter Coefficient and exponent for Node 2

5

2

Do u want to create another node

N

Traversal of Polynomial Linked List 1

6x^3 + 8x^2



Traversal of Polynomial Linked List 2

7x^3 + 5x^2



Traversal of Polynomial Linked List after adding Temp1 & Temp2

-1X^3 + 3X^2 THE END

Program in C to add two polynomials.

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#define NULL 0

void main()

{

struct poly

{

int coff;

int expo;

struct poly *link;

}*temp1,*start1,*temp2,*start2,*start3,*temp3;

int n,i,z=1,num;

char c;

clrscr();

start1=NULL;

printf("\tPOLYNOMIAL CREATION IN LINK LIST AND ADDITION\n\n");

while(1)

{

if(start1==NULL)

{

temp1=(struct poly*)malloc(sizeof(struct poly));

printf("Enter Coefficient and Exponent for Node %d\n",z);

scanf("%d %d",&temp1->coff,&temp1->expo);

start1=temp1;

temp1->link=NULL;

}

else

{

temp1->link=(struct poly*)malloc(sizeof(struct poly));

temp1=temp1->link;

printf("Enter Coefficient and exponent for Node %d\n",z);

scanf("%d %d",&temp1->coff,&temp1->expo);

}

z++;

printf("Do you want to create another node\n");

fflush(stdin);

scanf("%c",&c);

if(c!='y')

{

temp1->link=NULL;

break;

}

}

start2=NULL;

temp2=NULL;

z=1;

while(1)

{

if(start2==NULL)

{

temp2=(struct poly*)malloc(sizeof(struct poly));

printf("Enter Coefficient and exponent for Node %d\n",z);

scanf("%d %d",&temp2->coff,&temp2->expo);

start2=temp2;

temp2->link=NULL;

}

else

{

temp2->link=(struct poly*)malloc(sizeof(struct poly));

temp2=temp2->link;

printf("Enter Coefficient and exponent for Node %d\n",z);

scanf("%d %d",&temp2->coff,&temp2->expo);

}

z++;

printf("Do you want to create another node\n");

fflush(stdin);

scanf("%c",&c);

if(c!='y')

{

temp2->link=NULL;

break;

}

}

// TARVERSING

temp1=NULL;

temp2=NULL;

temp1=start1;

temp2=start2;

printf("Traversal of Polynomial Linked List 1\n");

while(temp1!=NULL)

{

printf("%2dx^%d+",temp1->coff,temp1->expo);

temp1=temp1->link;

}

printf("\b\b");

printf("\nTraversal of Polynomial Linked List 2\n");

while(temp2!=NULL)

{

printf("%2dx^%d+",temp2->coff,temp2->expo);

temp2=temp2->link;

}

printf("\b\b");

// addition

temp1=NULL;

temp2=NULL;

temp1=start1;

temp2=start2;

temp3=NULL;

start3=NULL;

while(1)

{

if((temp1!=NULL)||(temp2!=NULL))

{

if(start3==NULL)

{

if((temp1->expo)==(temp2->expo))

{

temp3=(struct poly*)malloc(sizeof(struct poly));

temp3->coff= (temp1->coff) + (temp2->coff);

temp3->expo=temp1->expo;

start3=temp3;

temp1=temp1->link;

temp2=temp2->link;

temp3->link=NULL;

}

else if(temp1->expo>temp2->expo)

{

temp3=(struct poly*)malloc(sizeof(struct poly));

temp3->coff=temp1->coff;

temp3->expo=temp1->expo;

start3=temp3;

temp1=temp1->link;

temp3->link=NULL;

}

else

{

temp3=(struct poly*)malloc(sizeof(struct poly));

temp3->coff=temp2->coff;

temp3->expo=temp2->expo;

start3=temp3;

temp2=temp2->link;

temp3->link=NULL;

}

}

else

{

if(temp1->expo==temp2->expo)

{

temp3->link=(struct poly*)malloc(sizeof(struct poly));

temp3=temp3->link;

temp3->coff= (temp1->coff) + (temp2->coff);

temp3->expo=temp1->expo;

temp1=temp1->link;

temp2=temp2->link;

}

else if(temp1->expo>temp2->expo)

{

temp3->link=(struct poly*)malloc(sizeof(struct poly));

temp3=temp3->link;

temp3->coff=temp1->coff;

temp3->expo=temp1->expo;

temp1=temp1->link;

}

else

{

temp3->link=(struct poly*)malloc(sizeof(struct poly));

temp3=temp3->link;

temp3->coff=temp2->coff;

temp3->expo=temp2->expo;

temp2=temp2->link;

}

}

}

else

break;

}

temp3->link=NULL;

//traversing temp3

temp3=NULL;

temp3=start3;

printf("\nTraversal of Polynomial Linked List after adding Temp1 & Temp2\n");

while(temp3!=NULL)

{

printf("%2dx^%d + ",temp3->coff,temp3->expo);

temp3=temp3->link;

} printf("\b \b");

getch();

}

OUTPUT:

POLYNOMIAL CREATION IN LINK LIST AND ADDITION



Enter Coefficient and exponent for Node 1

6

3

Do you want to create another node

Y

Enter Coefficient and exponent for Node 2

8

2

Do u want to create another node

N

Enter Coefficient and exponent for Node 1

7

3

Do you want to create another node

Y

Enter Coefficient and exponent for Node 2

5

2

Do u want to create another node

N

Traversal of Polynomial Linked List 1

6x^3 + 8x^2



Traversal of Polynomial Linked List 2

7x^3 + 5x^2



Traversal of Polynomial Linked List after adding Temp1 & Temp2

13X^3 +13X^2

program in C to store any polynomial using linked list.



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define NULL 0
void main()
 {
  struct poly
   {
    int coff;
    int expo;
    struct poly *link;
   }*temp,*start,*n1,*prev;
  int n,i,z=1,num;
  char c;
  clrscr();
  start=NULL;
  n1=NULL;
  printf("\tPOLYNOMIAL CREATION IN LINK LIST AND TRAVERSAL\n\n");
  while(1)
   {
    if(start==NULL)
     {
                temp=(struct poly*)malloc(sizeof(struct poly));
                printf("Enter Coefficient and exponent for Node %d\n",z);
                scanf("%d %d",&temp->coff,&temp->expo);
                start=temp;
                temp->link=NULL;
       }
     else
     {
      temp->link=(struct poly*)malloc(sizeof(struct poly));
      temp=temp->link;
      printf("Enter Coefficient and exponent for Node %d\n",z);
      scanf("%d %d",&temp->coff,&temp->expo);
     }
       z++;
      printf("Do you want to create another node\n");
      fflush(stdin);
      scanf("%c",&c);
      if(c!='y')
       {
                temp->link=NULL;
                break;
       }
     }
   // TARVERSING
  n1=start;
  printf("Traversal\n");
  while(n1!=NULL)
   {
    printf(" %2dx^%d  + ",n1->coff ,n1->expo);
    n1=n1->link;
   }
   printf("\b\b\nTHE END\n");
 getch();
}


Output:

                 POLYNOMIAL CREATION IN LINK LIST AND TRAVERSAL
Enter Coefficient and exponent for Node 1
6
3
Do you want to create another node
Y
Enter Coefficient and exponent for Node 2
8
2
Do u want to create another node
N
Traversal
6x^3  + 8x^2
THE END

Thursday 5 April 2012

idea free caller tune for one month..

dial 54444 from ur idea mobile to get 1 month free caller tune................




njoy..............................

Monday 2 April 2012

Get all latest updates from google for free



 Now u can get all the information's
to get just dial 180041999999(toll free) and say your needs then you will receive an sms relevant to your needs.

Eg: if you want meaning for a particular word just call and say the word the relevant meaning will be sent through sms

how to get puk number of airtel


Sim locked?
need to unlock it?
just type your mobile number and sent to 785
immediately your will receive your PUK code and PIN code directly into your inbox.,

Enjoy.,!!

AIRTEL FREE MISS CALL ALERTS


Friends here is the new trick for airtel miss call alert...

Just Type OFFER and send it to 54321

You will receive a message from Airtel

Thank you for subscribing to MCA service. Your activation request is under process You will receive a confirmation SMS shortly. After some time you will get a activation message .

change ur windows XP password using command



Below are the steps how to change the XP password using command


-Start-> Run
-Open Cmd
-Type "net user "
-ENTER
-Ask for New Password
-Give Password Which you Want -Twice ENTER 


Thats it
Your password gets changed
Try and post your comments here........................

C Program for Circular Queue implementation through Array



//Program for Circular Queue implementation through Array
#include <stdio.h>
#include<conio.h>
#define MAXSIZE 5
int cq[MAXSIZE]={0};
int front,rear;
void main()
{
void add(int);
void del();
void display();
int ch,i,num;
front = -1;
rear = -1;
clrscr();
printf("\nProgram for Circular Queue demonstration through array");
while(1)
{
printf("\n\nMAIN MENU\n1.INSERTION\n2.DELETION\n3.DISPLAY\n4.EXIT");
printf("\n\nENTER YOUR CHOICE : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n\nENTER THE QUEUE ELEMENT : ");
scanf("%d",&num);
add(num);
break;
case 2:
del();
break;
case 3:
   display();
    break;
case 4:
    exit(0);
default: printf("\n\nInvalid Choice . ");
}

}
}


void add(int item)
{
if(front ==(rear+1)%MAXSIZE)
{
printf("\n\nCIRCULAR QUEUE IS OVERFLOW");
}
else
{
 if(front==-1)
   front=rear=0;
   else
   rear=(rear+1)%MAXSIZE;
   cq[rear]=item;
   printf("\n\nRear = %d    Front = %d ",rear,front);
}
}


void del()
{
int a;
if(front == -1)
{
printf("\n\nCIRCULAR QUEUE IS UNDERFLOW");
}
else
{
a=cq[front];
 cq[front]=0;
if(front==rear)
front=rear=-1;
else
 front = (front+1)%MAXSIZE;
printf("\n\nDELETED ELEMENT FROM QUEUE IS : %d ",a);
printf("\n\nRear = %d    Front = %d ",rear,front);

}
}

void display()
{
 int i;
 for(i=0;i<MAXSIZE;i++)
   printf("%d\t",cq[i]);
}

Sunday 1 April 2012

C Program to implement NEWTON'S BACKWARD METHOD OF INTEROLATION


/*
  Program to implement NEWTON'S BACKWARD METHOD OF INTEROLATION.
      ----------------------------------------

*/

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

void main()
{
int n;                          // no. of terms.
int i,j,k;                      // Loop variables
float mx[10];                   // 'X' array limit 9
float my[10];                   // 'Y' array limit 9
float x;                        // User Query for what value of X
float x0=0;                     //
float y0;                       // Value coressponding to x0.
float sum=0;                      // Calculated value for coressponding X.
float h;                        // Calc. Section
float fun=0;                      //
float p;                        // Calc. Section
float diff[20][20];             // to store Y
float y1,y2,y3,y4;              // Formulae variables.

clrscr();
// Input section.

printf("\t\t !! NEWTON'S GREGORY BACKWARD INTERPOLATION FORMULA !! ");
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&mx[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&my[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
h=mx[1]-mx[0];
for(i=0;i<n-1;i++)
   diff[i][1]=my[i+1]-my[i];

for(j=2;j<=4;j++)
   for(i=0;i<n-j;i++)
      diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
i=0;

while(!mx[i]>x)
     i++;

x0=mx[i];
sum=0;

y0=my[i];
fun=1;

p=(x-x0)/h;
sum=y0;

for(k=1;k<=4;k++)
   {
   fun=(fun*(p-(k-1)))/k;
   sum=sum+fun*diff[i][k];
   }

// Outut Section
printf("\n When x = %6.4f , y = %6.8f",x,sum);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}

C Program to implement NEWTON'S FORWARD METHOD OF INTEROLATION


/*
  Program to implement NEWTON'S FORWARD METHOD OF INTEROLATION.
      --------------------------------------
*/

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

void main()
{
int n;                          // no. of terms.
int i,j;                        // Loop variables
float ax[10];                   // 'X' array limit 9
float ay[10];                   // 'Y' array limit 9
float x;                        // User Query for what value of X
float y=0;                      // Calculated value for coressponding X.
float h;                        // Calc. Section
float p;                        // Calc. Section
float diff[20][20];             // to store Y
float y1,y2,y3,y4;              // Formulae variables.

clrscr();
printf("\t\t !! NEWTON'S GREGORY FORWARD INTERPOLATION FORMULA !! ");
// Input section.
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&ax[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&ay[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
h=ax[1]-ax[0];

// for 1.
for(i=0;i<n-1;i++)
   diff[i][1]=ay[i+1]-ay[i];
// for 2, 3, 4
for(j=2;j<=4;j++)
   for(i=0;i<n-j;i++)
      diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

do
 {
 i++;
 }
 while(ax[i]<x);
i--;

p=(x-ax[i])/h;
y1=p*diff[i-1][1];                                            // 1
y2=p*(p+1)*diff[i-1][2]/2;                                    // 2
y3=p*(p+1)*(p-1)*diff[i-2][3]/6;                              // 3
y4=(p+2)*(p+1)*p*(p-1)*diff[i-3][4]/24;

// Taking sum
y=ay[i]+y1+y2+y3+y4;

// Outut Section
printf("\n When x = %6.4f , y = %6.8f",x,y);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");


getch();
}

C Program to Implement REGULAR FALSI (FALSE POSITION) METHOD


/*
  Program to Implement REGULAR FALSI (FALSE POSITION) METHOD.
  EQN -> 3*x + sin(x) - exp(x) = 0.
*/

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

// Formulae Declaration
#define EPS 0.00005
#define f(x)  3*x + sin(x) - exp(x)
int n;

void FAL_POS();

void main()
{
clrscr();
printf("\n Solution by ITERATION METHOD ");
printf("\n\n Equation is -> x*x*x - 2*x + 1 = 0\n");
printf("\n Enter the no. of iterations ");
scanf("%d",&n);
FAL_POS();
getch();
}

void FAL_POS()
 {
 long float x1,x2,x0;
 float f1,f2,f0;
 int itr=n,i;
 for(x1=0.0;;)
    {
    f1=f(x1);
    if(f1>0)
      break;
    else
      x1=x1+0.1;
    }
 x0=x1-0.1;
 f0=f(x0);
 printf("\n\t\t----------------------------------------------------");
 printf("\n \t\tITERATION\t x2\t\t\t   F(X)\n");
 printf("\n\t\t----------------------------------------------------\n");
 for(i=0;i<itr;i++)
    {
    x2=x0-((x1-x0)/(f1-f0))*f0;
    f2=f(x2);
    if(f0*f2>0)
      {
      x1=x2;
      f1=f2;
      }
    else
      {
      x0=x2;
      f0=f2;
      }
    if(fabs(f(2))>EPS)
      printf("\n\t\t %d \t\t %f \t\t %f \n",i+1,x2,f2);
    }
 printf("\n\n\n\t\t----------------------------------------------------");
 printf("\n\t\t ROOT  = %f ",x2);
 printf("\n\t\t----------------------------------------------------");
}

C Program to Implement NEWTON RAPHSON METHOD


/*
  Program to Implement NEWTON RAPHSON METHOD to solve eqn.
  EQN -> 3*x - cos(x) - 1 = 0.
*/

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

// Formulae Declaration
#define f(x)   3*x - cos(x) - 1
#define df(x)  3+sin(x)
int n;

void NEW_RAP();

void main()
{
clrscr();
printf("\n Solution by NEWTON RAPHSON METHOD ");
printf("\n\n Equation is -> 3*x - cos(x) - 1 = 0\n");
printf("\n Enter the no. of iterations ");
scanf("%d",&n);
NEW_RAP();
getch();
}

void NEW_RAP()
 {
 float x1,x0;
 float f1,f0;
 float df0;
 int i=1,itr;
 float EPS,error;

 /* finding an approximate Root of a given equation, having +ve value*/
 for(x1=0.0;;x1+=0.01)
    {
    f1=f(x1);
    if(f1>0)
      break;
    }
 itr=n;
 x0=x1-0.01;
 f0=f(x0);
 printf("\n Enter the Maximum possible error: ");
 scanf("%f",&EPS);
 if(fabs(f0)>f1)
   printf("\n\t\t The root is near to %.4f\n\n\n",x1);
 if(f1>fabs(x0))
   printf("\n\t\t The root is near to %.4f\n\n\n",x0);
 x0=(x0+x1)/2;
 for(;i<=itr;i++)
    {
    f0=f(x0);
    df0=df(x0);
    x1=x0-(f0/df0);
    printf("\n\t\t The %d approximation to the root is : %f",i,x1);
    error=fabs(x1-x0);
    if(error<EPS)
      break;
    x0=x1;
    }
 if(error>EPS)
   {
   printf("\n\n\t NOTE :-");
   printf(" The No. of Iterartions are not sufficient. ");
   }
 printf("\n\n\n\t\t----------------------------------------------------");
 printf("\n\t\t ROOT  = %.4f ",x1);
 printf("\n\t\t----------------------------------------------------");
}

Program to implement LANGRANGE'S INTERPOLATION FORMULA in C

/*
  Program to implement LANGRANGE'S INTERPOLATION FORMULA in C.
      ----------------------------------------------
*/

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

void main()
{
int n;                          // no. of terms.
int i,j;                        // Loop variables
float ax[100];                   // 'X' array limit 9
float ay[100];                   // 'Y' array limit 9
float x=0;                        // User Query for what value of X
float y=0;                      // Calculated value for coressponding X.
float nr,dr;

clrscr();
printf("\t\t !! LANGRANGE'S INTERPOLATION FORMULA !! ");
// Input section.
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&ax[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&ay[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
for(i=0;i<n;i++)
   {
   nr=1;
   dr=1;
   for(j=0;j<n;j++)
      {
      if(j!=i)
{
nr=nr*(x-ax[j]);
dr=dr*(ax[i]-ax[j]);
}
      y+=(nr/dr)*ay[i];
      }
   }
// Outut Section
printf("\n When x = %5.2f , y = %5.2f",x,y);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}

C Program to Implement ITERATION METHOD


/*
  Program to Implement ITERATION METHOD.
  EQN -> x*x*x - 2*x + 1 = 0.
*/

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

#define EPS 0.00005
#define F(x) (x*x*x + 1)/2
#define f(x)  x*x*x - 2*x + 1

int n;

void iter();

void main()
{
clrscr();
printf("\n Solution by ITERATION METHOD ");
printf("\n\n Equation is -> x*x*x - 2*x + 1 = 0\n");
printf("\n Enter the no. of iterations ");
scanf("%d",&n);
iter();
getch();
}

void iter()
 {
 int i=0;
 float x1,x2,x0;
 float f1,f2,f0,error;
 for(x1=1; ;x1++)
    {
    f1=f(x1);
    if(f1>0)
      break;
    }
 for(x0=x1-1; ;x0--)
    {
    f0=f(x0);
    if(f0<0)
      break;
    }
 x2=(x0+x1)/2;
 printf("\n\n\t\t The 1 approximatrion to the root is : %f",x2);
 for(;i<n-1;i++)
    {
    f2=F(x2);
    printf("\n\n\t\t The %d approximatrion to the root is : %f",i+2,f2);
    x2=F(x2);
    error=fabs(f2-f1);
    if(error<EPS)
       break;
    f1=f2;
    }
 if(error>EPS)
   printf("\n\n\t NOTE :- The no. of iterations are not sufficient.");
 printf("\n\n\n\t\t -----------------------------------------------");
 printf("\n\t\t ROOT  = %.4f (Correct to 4 Decimal places)",f2);
 printf("\n\t\t -----------------------------------------------");
}


C Program to implement GAUSS' FORWARD INTERPOLATION FORMULA


/*
  Program to implement GAUSS' FORWARD INTERPOLATION FORMULA.
      ---------------------------------
*/

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

void main()
{
int n;                          // no. of terms.
int i,j;                        // Loop variables
float ax[10];                   // 'X' array limit 9
float ay[10];                   // 'Y' array limit 9
float x;                        // User Query for what value of X
float nr,dr;
float y=0;                      // Calculated value for coressponding X.
float h;                        // Calc. Section
float p;                        // Calc. Section
float diff[20][20];             // to store Y
float y1,y2,y3,y4;              // Formulae variables.

clrscr();
printf("\t\t !! GAUSS' FORWARD INTERPOLATION FORMULA !! ");
// Input section.
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&ax[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&ay[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
h=ax[1]-ax[0];
for(i=0;i<n-1;i++)
   diff[i][1]=ay[i+1]-ay[i];

for(j=2;j<=4;j++)
   for(i=0;i<n-j;i++)
      diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

i=0;
do
 {
 i++;
 }
while(ax[i]<x);

i--;
p=(x-ax[i])/h;
y1=p*diff[i][1];
y2=p*(p-1)*diff[i-1][2]/2;
y3=(p+1)*p*(p-1)*diff[i-2][3]/6;
y4=(p+1)*p*(p-1)*(p-2)*diff[i-3][4]/24;

// Taking sum
y=ay[i]+y1+y2+y3+y4;

// Outut Section
printf("\n When x = %6.4f , y = %6.8f",x,y);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}

c Program to implement GAUSS' BACKWARD INTERPOLATION FORMULA


/*
  Program to implement GAUSS' BACKWARD INTERPOLATION FORMULA
*/

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

void main()
{
int n;                          // no. of terms.
int i,j;                        // Loop variables
float ax[10];                   // 'X' array limit 9
float ay[10];                   // 'Y' array limit 9
float x;                        // User Query for what value of X
float y=0;                      // Calculated value for coressponding X.
float h;                        // Calc. Section
float p;                        // Calc. Section
float diff[20][20];             // to store Y
float y1,y2,y3,y4;              // Formulae variables.

clrscr();
printf("\t\t !! GAUSS' FORWARD INTERPOLATION FORMULA !! ");
// Input section.
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&ax[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&ay[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
h=ax[1]-ax[0];
for(i=0;i<n-1;i++)
   diff[i][1]=ay[i+1]-ay[i];

for(j=2;j<=4;j++)
   for(i=0;i<n-j;i++)
      diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

i=0;
do
 {
 i++;
 }
while(ax[i]<x);

i--;
p=(x-ax[i])/h;
y1=p*diff[i-1][1];
y2=p*(p+1)*diff[i-1][2]/2;
y3=(p+1)*p*(p-1)*diff[i-2][3]/6;
y4=(p+2)*(p+1)*p*(p-1)*diff[i-3][4]/24;

// Taking sum
y=ay[i]+y1+y2+y3+y4;

// Outut Section
printf("\n When x = %6.4f , y = %6.4f",x,y);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}

c Program to Implement BISECTION METHOD


/*
  Program to Implement BISECTION METHOD.
  EQN -> x*log10(x) - 1.2
*/

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

#define F(x)  (x)*log10(x)-1.2
int n;
float root=1;

void bisect();

void main()
{
clrscr();
printf("\n Solution by BISECTION METHOD ");
printf("\n Equation is -> x*log(x) - 1.2 = 0\n");
printf("\n Enter the no. of iterations ");
scanf("%d",&n);
bisect();
getch();
}

void bisect()
 {
 int count;
 float x1,x2,x0;
 float f1,f2,f0;
 // Finding x2
 for(x2=1; ;x2++)
    {
    f2=F(x2);
    if(f2>0)
      {
      break;
      }
    }
 printf("\n x2 = %d ",x2);
 // Finding x1
 for(x1=x2-1; ;x1--)
    {
    f1=F(x1);
    if(f1<0)
      {
      break;
      }
    }
 printf("\n x2 = %d ",x2);
 printf("\n ----------------------------------------------------");
 printf("\n \tIteration No.    \t -        ROOTS ");
 printf("\n ----------------------------------------------------\n");
 for(count=1;count<=n;count++)
    {
    x0=(x1+x2)/2;
    f0=F(x0);
    if(f0==0)
      {
      root=x0;
      }
    if(f0*f1<0)
      {
      x2=x0;
      f2=f0;
      }
    else
      {
      x1=x0;
      f1=f0;
      }
    printf("\n \t ITERATION %d \t : \t %f",count,x0);
    if( fabs((x1-x2)/2) < 0.00000005)
      {
      printf("\n -----------------------------------------------");
      printf("\n \t \t \tROOT       = %f ",x0);
      printf("\n \t \t \tITERATIONS = %d ",count);
      printf("\n -----------------------------------------------");
      exit(0);
      }
    }
printf("\n ----------------------------------------------------");
printf("\n \t \t    ROOT       = %7.4f ",x0);
printf("\n \t \t    ITERATIONS = %d ",count-1);
printf("\n ----------------------------------------------------");
}

Thursday 29 March 2012

tips nd tricks section added soon

Tips nd tricks section added soon. Pls give ur comment nd suggestion to improve this blog.

Tuesday 27 March 2012

Program to implement LAPLACE - EVERETT'S INTERPOLATION FORMULA in C



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

void main()
{
int n;                          // no. of terms.
int i,j;                        // Loop variables
float ax[10];                   // 'X' array limit 9
float ay[10];                   // 'Y' array limit 9
float x;                        // User Query for what value of X
float nr,dr;
float y=0;                      // Calculated value for coressponding X.
float h;                        // Calc. Section
float p,q;                      // Calc. Section
float diff[20][20];             // to store Y
float y1,y2,y3,y4;              // Formulae variables.
float py1,py2,py3,py4;

clrscr();
printf("\t\t !! LAPALCE-EVERETT'S INTERPOLATION FORMULA !! ");
// Input section.
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&ax[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&ay[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
h=ax[1]-ax[0];
for(i=0;i<n-1;i++)
   diff[i][1]=ay[i+1]-ay[i];

for(j=2;j<=4;j++)
   for(i=0;i<n-j;i++)
      diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

i=0;
do
 {
 i++;
 }
while(ax[i]<x);

i--;
p=(x-ax[i])/h;
q=1-p;
y1=q*(ay[i]);
y2=q*(q*q-1)*diff[i-1][2]/4;
y3=q*(q*q-1)*(q*q-4)*diff[i-2][4]/120;
py1=p*(ay[i+1]);
py2=p*(p*p-1)*diff[i][2]/6;
py3=p*(p*p-1)*(p*p-4)*diff[i-1][4]/120;

// Taking sum
y=ay[i]+y1+y2+y3+py1+py2+py3;

// Outut Section
printf("\n When x = %6.2f , y = %6.8f",x,y);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}

program in to implement Gauss Seidal method



# include <stdio.h>
# include <conio.h>
# include <math.h>
# define MAXIT 50
# define EPS .000001
void main()
{
float a[10][10],b[10],x[10],sum,x0[10];
int i,j,n,count=0;
clrscr();
printf("Enter Number of equation : ");
scanf("%d",&n);
printf("Enter Coefficients row by row \n");
printf("One row in each line\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%f",&a[i][j]);
printf("Enter vector elements\n");
for(i=1;i<=n;i++)
{
x0[i]=x[i]=0;
scanf("%f",&b[i]);
}
printf("N\t");
for(i=1;i<=n;i++)
printf("X%d \t",i);
printf("\n");
printf("-------------------------------------------------------------------\n");
s: printf("%d\t",count+1);
for(i=1;i<=n;i++)
{
sum=0;
for(j=1;j<=n;j++)
{
if(i==j)
continue;
else
sum=sum+(a[i][j]*x[j]);
}
x[i]=(b[i]-sum)/a[i][i];
printf("%f \t",x[i]);
}
count++;
if(fabs(x[n]-x0[n])>EPS && count<MAXIT)
{
for(i=1;i<=n;i++)
x0[i]=x[i];
printf("\n");
goto s;
}
else
{
printf("\n----------------------------------------------\nSolution : \n");
for(i=1;i<=n;i++)
printf("X%d = %3.4f\t",i,x[i]);
}
getch();
}

Newton Divided difference formula



# include <stdio.h>
# include <conio.h>
# define MAX 20
void main()
{
int i,j,n;
float x[MAX],fx[MAX][MAX],xp,u,sum=0;
printf("Newton Divided Difference formula \n");
printf("Enter No. of data points : ");
scanf("%d",&n);
printf("Enter values of X and f(x) set by set each at once \n");
for(i=1;i<=n;i++)
scanf("%f%f",&x[i],&fx[i][1]);
printf("Enter value of X at which interpolation is required : ");
scanf("%f",&xp);
for(i=2;i<=n;i++)
for(j=1;j<=n-i+1;j++)
fx[j][i]=(fx[j+1][i-1]-fx[j][i-1])/(x[j+i-1]-x[j]);
printf("-------------------------------------------------------------------\n");
printf("X F(x) ");
for(i=1;i<n;i++)
printf("y%d ",i);
printf("\n-----------------------------------------------------------------\n");
for(i=1;i<=n;i++)
{
printf("%4.2f\t ",x[i]);
for(j=1;j<=n-i+1;j++)
printf("%4.2f ",fx[i][j]);
printf("\n");
}
printf("\n-----------------------------------------------------------------\n");
sum=fx[1][1];
for(i=2;i<=n;i++)
{
u=1;
for(j=1;j<i;j++)
u=u*(xp-x[j]);
u=u*fx[1][i];
sum=sum+u;
}
printf("For %3.2f Interpolated value = %4.2f",xp,sum);
getch();
}

Monday 26 March 2012

first experience of blogging

This blog is for all computer learners. my goal to make this blog for c beginners and data structure students. i will try my best to update this on daily basis, so plz visit this . and say that you like this or not. and how can i make this better. thanx.

Sunday 25 March 2012

Program to implement BESSELS INTERPOLATION FORMULA in C


/*
  Program to implement BESSELS INTERPOLATION FORMULA in C.
      ------------------------------------
*/

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

void main()
{
int n;                          // no. of terms.
int i,j;                        // Loop variables
float ax[10];                   // 'X' array limit 9
float ay[10];                   // 'Y' array limit 9
float x;                        // User Query for what value of X
float y;                      // Calculated value for coressponding X.
float h;                        // Calc. Section
float p;                        // Calc. Section
float diff[20][20];             // to store Y
float y1,y2,y3,y4;              // Formulae variables.

clrscr();
printf("\t\t !! BESSELS INTERPOLATION FORMULA !! ");
// Input section.
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);

// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of x%d -> ",i+1);
   scanf("%f",&ax[i]);
   }

// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
   {
   printf("\n Enter the value of y%d -> ",i+1);
   scanf("%f",&ay[i]);
   }

// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);

// Calculation and processing section.
h=ax[1]-ax[0];
for(i=0;i<n-1;i++)
   diff[i][1]=ay[i+1]-ay[i];

for(j=2;j<=4;j++)
   for(i=0;i<n-j;i++)
      diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

i=0;
do
 {
 i++;
 }
while(ax[i]<x);

i--;
p=(x-ax[i])/h;
y1=p*diff[i][1];
y2=p*(p-1)*(diff[i][2]+diff[i-1][2])/4;
y3=p*(p-1)*(p-0.5)*diff[i-1][3]/6;
y4=(p+1)*p*(p-1)*(p-2)*(diff[i-2][4]+diff[i-1][4])/48;

// Taking sum
y=ay[i]+y1+y2+y3+y4;

// Outut Section
printf("\n When x = %6.2f , y = %6.8f",x,y);

// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}

program to create two way linked list


program to create two way linked list.

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#define NULL 0
void main()
{
struct dnode
{
struct dnode *prev;
int data;
struct dnode *next;
}*start,*temp,*k,*p,*pre;
int i,c;
char ch;
clrscr();
start=NULL;
for(i=0;i<=1;i++)
{
if(start==NULL)
{
temp=(struct dnode*)malloc(sizeof(struct dnode));
printf("\nEnter the value for node: -");
scanf("%d",&temp->data);
start= temp;
temp->prev=NULL;
temp->next=NULL;
}
else
{
while(1)
{
printf("\nDo you want to create one more node(Y/N):- ");
fflush(stdin);
scanf("%c",&ch);
if(ch=='y' || ch=='Y')
{
temp->next=(struct dnode*)malloc(sizeof(struct dnode));
printf("\nEnter the value of  node: -");
k=temp->next;
scanf("%d",&k->data);
k->prev=temp;
k->next=NULL;
temp=k;
}
else
{
temp->next=NULL;
break;
}
}
}
}
//For forward Displaying the linked list.
printf("\n\n\nBy forward Displaying: -");
printf("\nNodes of linked list are-\n");
temp=start;
while(temp!=NULL)
{
printf("%4d",temp->data);
temp=temp->next;
}
//For backward Displaying the linked list.
printf("\n\n\nBy backward Displaying:");
printf("\nNodes of linked list are-\n");
temp=k;
while(temp!=NULL)
{
printf("%4d",temp->data);
temp=temp->prev;
}
getch();
}

output:
Enter the value for node: -14
Do you want to create one more node(Y/N):- y
Enter the value of  node: -63
Do you want to create one more node(Y/N):- y
Enter the value of  node: -87
Do you want to create one more node(Y/N):- y
Enter the value of  node: -69
Do you want to create one more node(Y/N):- y
Enter the value of  node: -100
Do you want to create one more node(Y/N):- n
By forward Displaying: -
Nodes of linked list are-
  14  63  87  69 100
By backward Displaying:
Nodes of linked list are-
 100  69  87  63 14