Cs 22
Cs 22
Cs 22
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() Interplanar Spacing
{
int i,n;
float x[15],y[15]; #include<stdio.h>
float sumx=0.0,sumy=0.0,sumxy=0.0,sumxsq=0.0,a,b; #include<conio.h>
clrscr();
printf("enter the number of data points:"); #include<math.h>
scanf("%d",&n); int main()
printf("enter the value of x:\n"); {
for(i=1;i<=n;i++)
{ float w1,d,s,pi;
scanf("%f",&x[i]); float c[6]={14,20,25,29.5,32.5,36.5};
} int n=1,i;
printf("enter the values of y:\n");
for(i=1;i<=n;i++) pi=3.142;
{ w1=1.54*pow(10,-10);
scanf("%f",&y[i]); for(i=0;i<6;i++)
}
for(i=1;i<=n;i++) {
{ d=(n*w1)/(2*sin(c[i]*(pi/180)));
sumx+=x[i]; s=(d*pow(10,10));
sumy+=y[i];
sumxy+=(x[i]*y[i]); printf("interplanar spacing at an angle
sumxsq+=(x[i]*x[i]); %.1f degree is %.3fE-10 \n",c[i],s);
}
}
b=(sumx*sumy-n*sumxy)/((sumx*sumx)-(n*sumxsq));
a=(sumy-b*sumx)/n; getch();
printf("the values of a=%f and b=%f",a,b); }
printf("the equation is y=(%f)x+(%f)",b,a);
getch();
}
Laguerre polynomial
#include<stdio.h> Output:
#include<conio.h>
#include<math.h>
the Laguerre polynomials are:
void main() x y1 y2 y3 y4
{
float x,y1,y2,y3,y4; 0.0 1.00 1.00 1.00 1.00
int i;
printf("the Laguerre polynomials 0.1 0.81 0.65 0.51 0.40
are:\n");
printf("x\ty1\ty2\ty3\ty4\t\n");
0.2 0.64 0.38 0.21 0.10
for(i=0;i<=10;i++) 0.3 0.49 0.20 0.05 0.00
{
x=(0.1*i); 0.4 0.36 0.08 0.00 0.03
y1=pow((1-x)/1,2);
y2=pow((pow(x,2)-(4*x)+2)/2,2); 0.5 0.25 0.02 0.02 0.11
y3=pow((pow(-x,3)+(9*(pow(x,2)))-
(18*x)+6)/6,2);
0.6 0.16 0.00 0.09 0.21
y4=pow((pow(x,4)- 0.7 0.09 0.02 0.18 0.30
(16*(pow(x,3)))+(72*(pow(x,2)))-
(96*x)+24)/24,2); 0.8 0.04 0.08 0.28 0.37
printf("%.1f\t%.2f\t%.2f\t%.2f\t%.2f\n"
,x,y1,y2,y3,y4); 0.9 0.01 0.16 0.37 0.40
}
1.0 0.00 0.25 0.44 0.39
getch ();
}
Hermite Polynomial Particle in 1-D box
#include<stdio.h> #include
#include<conio.h> #include
#include<math.h> #include
int main() void main()
{ {
float w1,d,s,pi; float h,m,l,energy;
float float e=1.6*pow(10,-19);
c[6]={14,20,25,29.5,32.5,36.5}; int n=5,i;
int n=1,i; clrscr();
pi=3.142; h=6.625*pow(10,-34);
w1=1.54*pow(10,-10); m=9.1*pow(10,-31);
for(i=0;i<6;i++) l=10*pow(10,-9);
{ for(i=1; i<=n; i++)
d=(n*w1)/(2*sin(c[i]*(pi/180))); {
s=(d*pow(10,10)); energy=((pow(i,2)*pow(h,2))/(8*m*pow(l,2)))/
printf("interplanar spacing at an e;
angle %.1f degree is %.3fE-10 printf("Energy of electron at n=%d is %.3f
\n",c[i],s); eV\n",i,energy);
} }
getch(); getch();
} }
printf("\n the transpose of matrix
printf("enter the order of matrix
printf("%d \t",a[i][j]);
printf("%d\t",a[j][i]);
int a[10][10],i,j,m,n;
scanf("%d",&a[i][j]);
scanf("%d%d",&m,&n);
#include<stdio.h>
#include<conio.h>
for(i=0;i<m;i++)
for(j=0;j<n;j++)
for(i=0;i<m;i++)
for(j=0;j<n;j++)
for(i=0;i<n;i++)
for(j=0;j<m;j++)
matrix a\n");
printf("\n");
printf("\n");
void main()
getch();
a:\n");
\n");
{
}
Multiplication of matrices
#include<stdio.h> Output:
#include<conio.h> the Hermite polynomials are:
void main()
{
x y1 y2 y3 y4
clrscr(); 0.0 0.00 4.00 0.00 144.00
int i,j,k,m,n,p,q; 0.1 0.04 3.84 1.42 132.75
int a[10][10],b[10][10],c[10][10]; 0.2 0.16 3.39 5.46 102.12
printf("\n enter the order of matrix a");
0.3 0.36 2.69 11.45 60.99
scanf("%d%d",&m,&n);
printf("\n enter the order of matrix b"); 0.4 0.64 1.85 18.39 22.37
scanf("%d%d",&p,&q); 0.5 1.00 1.00 25.00 1.00
printf("\n enter the elements of matrix a:"); 0.6 1.44 0.31 29.94 10.28
for(i=0;i<m;i++) 0.7 1.96 0.00 31.99 58.96
{
for(j=0;j<n;j++)
0.8 2.56 0.31 30.29 148.02
scanf("%d",&a[i][j]); 0.9 3.24 1.54 24.68 268.38
} 1.0 4.00 4.00 16.00 400.00
printf("\n enter the elements of matrix b:");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
} Factorial
printf("\n the matrix a:\n");
#include<stdio.h>
for(i=0;i<m;i++)
{
#include<conio.h>
for(j=0;j<n;j++) void main()
printf("%d\t",a[i][j]); {
printf("\n"); int i,n;
} float fact;
printf("\n the matrix b: \n");
clrscr();
for(i=0;i<p;i++)
{
printf("Enter a number\n");
for(j=0;j<q;j++) scanf("%d",&n);
printf("%d\t",b[i][j]); i=1; fact=1;
printf("\n"); while (i<=n)
} {
if(n==p)
fact=fact*i;
{
printf ("\n the matrix multiplication c:\n");
i++;
for(i=0;i<m;i++) }
{ printf("the factorial of %d is
for(j=0;j<q;j++) equal to %f",n,fact);
{ getch();
c[i][j]=0;
}
for (k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
else
printf("\n The matrix multiplication is not possible");
getch();
}