b[1]=-1
a[2][1]=3
a[2][2]=1
b[2]=2
The result is
x[1]=0.90
x[2]=-0.70
0
0
0.1
0.6
The required solution is 0.072234
Output:
Enter the value of x
0.5
The value of ln(1+x) for the given value of x
correct upto 4 decimal places is 0.4055
4; //A Program in C to find the value of e^x correct upto 4 decimal places
#include<stdio.h>
#include<math.h>
main(){
int factorial(int);
int i=1,n;
float x,sum=1.0,term;
printf("Enter the value of x \n");
scanf("%f",&x);
for(i=1;;i++){
term=(pow(x,i)/factorial(i));
if(term>0.000001)
sum=sum+term;
else
break;
}
printf("The value of exp(x) for x=%f correct upto 4decimal places is %1.4f",x,sum);
}
int factorial(int n){
int c,fact=1;
for(c=1;c<=n;c++)
fact=fact*c;
return fact;
}
output:
enter the value of x
value of exp(x) for x=0.500000 correct upto 4decimal places is 1.6487
int i=1,n;
float x,sum=1.0,term;
printf("Enter the value of x \n");
scanf("%f",&x);
for(i=1;;i++){
term=(pow(-x,i)/factorial(i));
if(fabs(term)>0.000001)
sum=sum+term;
else
break;
}
printf("The value of exp(-x) for x=%f correct upto 4 decimal places is %1.4f",x,sum);
}
int factorial(int n){
int c,fact=1;
for(c=1;c<=n;c++)
fact=fact*c;
return fact;
}
output:
the value of x
alue of exp(-x) for x=0.800000 correct upto 4 decimal places is 0.4493
6; /*A program in C to find the area of a triangle when its three sides are given*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
float a,b,c,s,s1,s2,s3,area;
clrscr();
printf("\n Enter the sides of the triangle:");
scanf("%f%f%f",&a,&b,&c);
s1=(a+b-c);
s2=(a+c-b);
s3=(b+c-a);
if( s1>0 && s2>0 && s3>0)
{
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\n the area of the triangle :%f",area);
}
else
{
printf("\n the triangle is not possible");
}
getch();
}
output:
Enter the sides of the triangle:12
22
11
the area of the triangle :36.856987
{
printf("\n");
for(j=0;j<p;j++)
printf("%d\t",b[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nThe multiplication of two matrices is\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<p;j++)
printf("%d\t",c[i][j]);
}
getch();
}
output:
Enter the First matrix->1
2
3
5
6
45
Enter the Second matrix->8
5
6
9
7
1
The First matrix is
1
2
3
5
6
45
The Second matrix is
8
5
6
9
7
1
The multiplication of two matrices is
41
391
26
12
a[j]=temp;
}
printf("After sorting, the numbers are in ascending order:\n ");
for(i=0;i<s;i++)
printf(" %d\n",a[i]);
getch();
}
output:
Enter total elements: 4
Now type the numbers: 12
34
56
87
After sorting, the numbers are in ascending order:
12
34
56
87
}
void main()
{
float a,b,h,sum,x0,xn,xi;
inti,n;
clrscr();
printf("Enter the lower and upper limit of the integration");
scanf("%f%f",&a,&b);
printf("Enter the number of intervals");
scanf("%d",&n);
h=(b-a)/n;
x0=a;
xn=b;
sum=funct(x0)+funct(xn);
for(i=1;i<n-1;i++)
{
xi=a+(i*h);
sum=sum+funct(xi)*2.0;
}
sum=(h/2.0)*sum;
printf("\n\n the required value of the integral is %5.3f",sum);
getch();
}
output:
Enter the lower and upper limit of the integration0
1
Enter the number of intervals10
the required value of the integral is 0.878
5
2
8
36
7
9
4
12
The matrix is
4
5
2
8
36
7
9
4
12
Inverse of matrix is:
0.47 -0.04 -0.34
-0.06 0.03 0.03
-0.04 -0.01 0.12
/*Write a program in c to find the Sum of first n natural numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series: ");
scanf("%d",&n);
sum = (n * (n + 1)) / 2;
printf("Sum of the series: ");
for(i =1;i <= n;i++)
{
if (i!=n)
printf("%d + ",i);
else
printf("%d= %d",i,sum);
}
getch();
}
output:
Enter the n i.e. max values of series: 6
Sum of the series: 1 + 2 + 3 + 4 + 5 + 6= 21
8
6
the matrix B is:
2
5
1
9
The Addition of two matrices is
9
14
9
15
output:
Enter the value of x in degrees:
30
The value of cos x for the given value of x
correct upto 4 decimal places is 0.8660
15; // A Program in C to find the roots of a quadratic equation with real coefficients
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float a,b,c,rp,ip;
float d,root1,root2,r;
printf("Enter a, b and c of quadratic equation: ");
scanf("%f%f%f",&a,&b,&c);
d = b * b - 4 * a * c;
if(d > 0)
{
printf("Roots are real numbers.\n");
root1 = ( -b + sqrt(d)) / (2* a);
16; /*A Program in C to find the solution of x3-8x-4=0 by using Newton Raphson
method*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return (pow(x,3)-8*x-4);
}
float f1(float x)
{
return (3*pow(x,2)-8);
}
void main()
{
float x,x1;
printf("enter the value of x");
scanf("%f",&x);
do
{
x1=x;
x=x-(f(x)/f1(x));
}
while(fabs(x-x1)>0.00001);
printf("%f",x);
getch();
}
output:
enter the value of x3
3.051374