0% found this document useful (0 votes)
11 views14 pages

Cs Lab

Uploaded by

Sanjay Sanjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

Cs Lab

Uploaded by

Sanjay Sanjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 14

Addition and subtraction of two numbers

Addition program:

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,b,sum;
printf("enter the values of a and b\n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("the sum of a and b=%d",sum);
getch();
}
Subtraction program :

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,b,diff;
printf("enter the values of a and b\n");
scanf("%d%d",&a,&b);
diff=a-b;
printf("the diff of a and b=%d",diff);
getch();
}
Multiplication and division of two numbers

Multiplication program:

#include<stdio.h>
#include<conio.h>
#include<math.h>
float main()
{
clrscr();
float a,b,c;
printf("enter the values of a and b\n");
scanf("%f%f",&a,&b);
c=a*b;
printf("the product of a and b=%f",c);
getch();
}
Division program:

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c;
printf("enter the values of a and b\n");
scanf("%f%f",&a,&b);
c=a/b;
printf("the division of two numbers a and b=%f",c);
getch();
}
Finding roots of a quadratic equation

Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
clrscr();
int a,b,c;
float disc, r1,r2;
printf("\n enter the coefficient of the quadratic equation:");
scanf("%d%d%d",&a,&b,&c);
disc=(b*b-4*a*c);
if(disc<0)
printf("\n the roots are imaginary\n");
else
{
r1=(-b+sqrt(disc))/(2*a);
r2=(-b-sqrt(disc))/(2*a);
printf ("\n the roots are: \n");
printf("\n the root1=%f",r1);
printf("\n the root2=%f",r2);
}
getch();
}
Factorial number

Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,fact;
clrscr();
printf("enter the number \n");
scanf("%d",&n);
i=1; fact=1;
while (i<=n)
{
fact=fact*i;
i++;
}
printf("the factorial of %d is equal to %d",n,fact);
getch();
}
Transpose of a matrix

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,m,n;
clrscr();
printf("enter the order of matrix \n");
scanf("%d%d",&m,&n);
printf("\n enter the elements of matrix a\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\n the matrix a: \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d \t",a[i][j]);
printf("\n");
}
printf("\n the transpose of matrix a:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%d\t",a[j][i]);
printf("\n");
}
getch();
]
Multiplication of two matrices

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,m,n,p,q;
int a[10][10],b[10][10],c[10][10];
clrscr();
printf("\n enter the order of matrix a");
scanf("%d%d",&m,&n);
printf("\n enter the order of matrix b");
scanf("%d%d",&p,&q);
printf("\n enter the elements of matrix a:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
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]);
}
printf("\n the matrix a:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("\n the matrix b: \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
if(n==p)
{
printf ("\n the matrix multiplication c:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
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();
}
Addition of matrices

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,m,n,p,q;
int a[10][10],b[10][10],sum[10][10];
clrscr();
printf("\n enter the order of matrix a");
scanf("%d%d",&m,&n);
printf("\n enter the order of matrix b");
scanf("%d%d",&p,&q);
printf("\n enter the elements of matrix a:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
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]);
}
printf("\n the matrix a:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("\n the matrix b: \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
printf("sum of two matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf ("%d\t",sum[i][j]);
}
printf("\n");
}
getch();
}
Subtraction of matrices
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,m,n,p,q;
int a[10][10],b[10][10],diff[10][10];
clrscr();
printf("\n enter the order of matrix a");
scanf("%d%d",&m,&n);
printf("\n enter the order of matrix b");
scanf("%d%d",&p,&q);
printf("\n enter the elements of matrix a:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
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]);
}
printf("\n the matrix a:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("\n the matrix b: \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
printf("diff of two matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
diff[i][j]=a[i][j]-b[i][j];
printf ("%d\t",diff[i][j]);
}
printf("\n");
}
getch();
}
The eigen values of a particle in 1-Dimensional box

Program;
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float h,m,I, energy;
float e=1.6*pow(10,-19);
int n=5,i;
clrscr();
h=6.625*pow(10,-34);
m=9.1*pow(10,-31);
I=10*pow(10,-9);
for(i=1;i<=n;i++)
{
energy=(((pow(i,2)*pow(h,2))/(8*m*pow(I,2))))/(e);
printf("energy of electron at n =%d is % d is %fev \n",i, energy);
}
getch();
}

You might also like