mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-11-29 23:45:34 +08:00
style: format code
This commit is contained in:
@@ -1,53 +1,53 @@
|
||||
#include<iostream.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
#include <iostream.h>
|
||||
#include <conio.h>
|
||||
#include <math.h>
|
||||
|
||||
float eq(float i)
|
||||
{
|
||||
return (pow(i,3)-(4*i)-9); // original equation
|
||||
return (pow(i, 3) - (4 * i) - 9); // original equation
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float a,b,x,z;
|
||||
float a, b, x, z;
|
||||
clrscr();
|
||||
for(int i=0;i<100;i++)
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
z=eq(i);
|
||||
if(z>=0)
|
||||
z = eq(i);
|
||||
if (z >= 0)
|
||||
{
|
||||
b=i;
|
||||
a=--i;
|
||||
b = i;
|
||||
a = --i;
|
||||
goto START;
|
||||
}
|
||||
}
|
||||
|
||||
START:
|
||||
START:
|
||||
|
||||
cout<<"\nFirst initial: "<<a;
|
||||
cout<<"\nSecond initial: "<<b;
|
||||
for(i=0;i<100;i++)
|
||||
cout << "\nFirst initial: " << a;
|
||||
cout << "\nSecond initial: " << b;
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
x=(a+b)/2;
|
||||
z=eq(x);
|
||||
cout<<"\n\nz: "<<z<<"\t["<<a<<" , "<<b<<" | Bisect: "<<x<<"]";
|
||||
x = (a + b) / 2;
|
||||
z = eq(x);
|
||||
cout << "\n\nz: " << z << "\t[" << a << " , " << b << " | Bisect: " << x << "]";
|
||||
|
||||
if(z < 0)
|
||||
if (z < 0)
|
||||
{
|
||||
a=x;
|
||||
a = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
b=x;
|
||||
b = x;
|
||||
}
|
||||
|
||||
if(z > 0 && z<0.0009) // stoping criteria
|
||||
if (z > 0 && z < 0.0009) // stoping criteria
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
cout<<"\n\nRoot: "<<x;
|
||||
END:
|
||||
cout << "\n\nRoot: " << x;
|
||||
getch();
|
||||
}
|
||||
|
||||
@@ -1,59 +1,63 @@
|
||||
#include<bits/stdc++.h>
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int mat_size,i,j,step;
|
||||
int mat_size, i, j, step;
|
||||
|
||||
cout<<"Matrix size: ";
|
||||
cin>>mat_size;
|
||||
cout << "Matrix size: ";
|
||||
cin >> mat_size;
|
||||
|
||||
double mat[mat_size+1][mat_size+1], x[mat_size][mat_size+1];
|
||||
double mat[mat_size + 1][mat_size + 1], x[mat_size][mat_size + 1];
|
||||
|
||||
cout<<endl<<"Enter value of the matrix: "<<endl;
|
||||
for(i=0;i<mat_size;i++)
|
||||
cout << endl
|
||||
<< "Enter value of the matrix: " << endl;
|
||||
for (i = 0; i < mat_size; i++)
|
||||
{
|
||||
for(j=0;j<=mat_size;j++)
|
||||
for (j = 0; j <= mat_size; j++)
|
||||
{
|
||||
cin>>mat[i][j]; //Enter (mat_size*mat_size) value of the matrix.
|
||||
cin >> mat[i][j]; //Enter (mat_size*mat_size) value of the matrix.
|
||||
}
|
||||
}
|
||||
|
||||
for(step=0;step<mat_size-1;step++){
|
||||
for(i=step;i<mat_size-1;i++)
|
||||
for (step = 0; step < mat_size - 1; step++)
|
||||
{
|
||||
for (i = step; i < mat_size - 1; i++)
|
||||
{
|
||||
double a = (mat[i+1][step]/mat[step][step]);
|
||||
double a = (mat[i + 1][step] / mat[step][step]);
|
||||
|
||||
for(j=step;j<=mat_size;j++)
|
||||
mat[i+1][j] = mat[i+1][j] - (a * mat[step][j]);
|
||||
for (j = step; j <= mat_size; j++)
|
||||
mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]);
|
||||
}
|
||||
}
|
||||
|
||||
cout<<endl<<"Matrix using Gaussian Elimination method: "<<endl;
|
||||
for(i=0;i<mat_size;i++)
|
||||
cout << endl
|
||||
<< "Matrix using Gaussian Elimination method: " << endl;
|
||||
for (i = 0; i < mat_size; i++)
|
||||
{
|
||||
for(j=0;j<=mat_size;j++)
|
||||
for (j = 0; j <= mat_size; j++)
|
||||
{
|
||||
x[i][j] = mat[i][j];
|
||||
cout<<mat[i][j]<<" ";
|
||||
cout << mat[i][j] << " ";
|
||||
}
|
||||
cout<<endl;
|
||||
cout << endl;
|
||||
}
|
||||
cout<<endl<<"Value of the Gaussian Elimination method: "<<endl;
|
||||
for(i=mat_size-1;i>=0;i--)
|
||||
cout << endl
|
||||
<< "Value of the Gaussian Elimination method: " << endl;
|
||||
for (i = mat_size - 1; i >= 0; i--)
|
||||
{
|
||||
double sum = 0;
|
||||
for(j=mat_size-1;j>i;j--)
|
||||
for (j = mat_size - 1; j > i; j--)
|
||||
{
|
||||
x[i][j] = x[j][j] * x[i][j];
|
||||
sum = x[i][j] + sum;
|
||||
}
|
||||
if(x[i][i]==0)
|
||||
if (x[i][i] == 0)
|
||||
x[i][i] = 0;
|
||||
else
|
||||
x[i][i] = (x[i][mat_size] - sum)/(x[i][i]);
|
||||
x[i][i] = (x[i][mat_size] - sum) / (x[i][i]);
|
||||
|
||||
cout<<"x"<<i<<"= "<<x[i][i]<<endl;
|
||||
cout << "x" << i << "= " << x[i][i] << endl;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
#include<iostream.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
#include <iostream.h>
|
||||
#include <conio.h>
|
||||
#include <math.h>
|
||||
|
||||
float eq(float i)
|
||||
{
|
||||
return (pow(i,3)-(4*i)-9); // original equation
|
||||
return (pow(i, 3) - (4 * i) - 9); // original equation
|
||||
}
|
||||
float eq_der(float i)
|
||||
{
|
||||
return ((3*pow(i,2))-4); // derivative of equation
|
||||
return ((3 * pow(i, 2)) - 4); // derivative of equation
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float a,b,z,c,m,n;
|
||||
float a, b, z, c, m, n;
|
||||
clrscr();
|
||||
for(int i=0;i<100;i++)
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
z=eq(i);
|
||||
if(z>=0)
|
||||
z = eq(i);
|
||||
if (z >= 0)
|
||||
{
|
||||
b=i;
|
||||
a=--i;
|
||||
b = i;
|
||||
a = --i;
|
||||
goto START;
|
||||
}
|
||||
}
|
||||
|
||||
START:
|
||||
START:
|
||||
|
||||
cout<<"\nFirst initial: "<<a;
|
||||
cout<<"\nSecond initial: "<<b;
|
||||
c=(a+b)/2;
|
||||
cout << "\nFirst initial: " << a;
|
||||
cout << "\nSecond initial: " << b;
|
||||
c = (a + b) / 2;
|
||||
|
||||
for(i=0;i<100;i++)
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
float h;
|
||||
m=eq(c);
|
||||
n=eq_der(c);
|
||||
m = eq(c);
|
||||
n = eq_der(c);
|
||||
|
||||
z=c-(m/n);
|
||||
c=z;
|
||||
z = c - (m / n);
|
||||
c = z;
|
||||
|
||||
if(m > 0 && m<0.009) // stoping criteria
|
||||
if (m > 0 && m < 0.009) // stoping criteria
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
cout<<"\n\nRoot: "<<z;
|
||||
END:
|
||||
cout << "\n\nRoot: " << z;
|
||||
getch();
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
#include<iostream.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
#include <iostream.h>
|
||||
#include <conio.h>
|
||||
#include <math.h>
|
||||
|
||||
float eq(float i)
|
||||
{
|
||||
return (pow(i,3)-(4*i)-9); // original equation
|
||||
return (pow(i, 3) - (4 * i) - 9); // original equation
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float a,b,z,c,m,n;
|
||||
float a, b, z, c, m, n;
|
||||
clrscr();
|
||||
for(int i=0;i<100;i++)
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
z=eq(i);
|
||||
if(z>=0)
|
||||
z = eq(i);
|
||||
if (z >= 0)
|
||||
{
|
||||
b=i;
|
||||
a=--i;
|
||||
b = i;
|
||||
a = --i;
|
||||
goto START;
|
||||
}
|
||||
}
|
||||
|
||||
START:
|
||||
START:
|
||||
|
||||
cout<<"\nFirst initial: "<<a;
|
||||
cout<<"\nSecond initial: "<<b;
|
||||
for(i=0;i<100;i++)
|
||||
cout << "\nFirst initial: " << a;
|
||||
cout << "\nSecond initial: " << b;
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
float h,d;
|
||||
m=eq(a);
|
||||
n=eq(b);
|
||||
float h, d;
|
||||
m = eq(a);
|
||||
n = eq(b);
|
||||
|
||||
c=((a*n)-(b*m))/(n-m);
|
||||
a=b;
|
||||
b=c;
|
||||
c = ((a * n) - (b * m)) / (n - m);
|
||||
a = b;
|
||||
b = c;
|
||||
|
||||
z=eq(c);
|
||||
if(z > 0 && z<0.09) // stoping criteria
|
||||
z = eq(c);
|
||||
if (z > 0 && z < 0.09) // stoping criteria
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
cout<<"\n\nRoot: "<<c;
|
||||
END:
|
||||
cout << "\n\nRoot: " << c;
|
||||
getch();
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
#include<iostream.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
#include <iostream.h>
|
||||
#include <conio.h>
|
||||
#include <math.h>
|
||||
|
||||
float eq(float i)
|
||||
{
|
||||
return (pow(i,3)-(4*i)-9); // origial equation
|
||||
return (pow(i, 3) - (4 * i) - 9); // origial equation
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float a,b,z,c,m,n;
|
||||
float a, b, z, c, m, n;
|
||||
clrscr();
|
||||
for(int i=0;i<100;i++)
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
z=eq(i);
|
||||
if(z>=0)
|
||||
z = eq(i);
|
||||
if (z >= 0)
|
||||
{
|
||||
b=i;
|
||||
a=--i;
|
||||
b = i;
|
||||
a = --i;
|
||||
goto START;
|
||||
}
|
||||
}
|
||||
|
||||
START:
|
||||
START:
|
||||
|
||||
cout<<"\nFirst initial: "<<a;
|
||||
cout<<"\nSecond initial: "<<b;
|
||||
for(i=0;i<100;i++)
|
||||
cout << "\nFirst initial: " << a;
|
||||
cout << "\nSecond initial: " << b;
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
|
||||
float h,d;
|
||||
m=eq(a);
|
||||
n=eq(b);
|
||||
float h, d;
|
||||
m = eq(a);
|
||||
n = eq(b);
|
||||
|
||||
c=((a*n)-(b*m))/(n-m);
|
||||
a=c;
|
||||
c = ((a * n) - (b * m)) / (n - m);
|
||||
a = c;
|
||||
|
||||
z=eq(c);
|
||||
if(z > 0 && z<0.09) // stoping criteria
|
||||
z = eq(c);
|
||||
if (z > 0 && z < 0.09) // stoping criteria
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
cout<<"\n\nRoot: "<<c;
|
||||
END:
|
||||
cout << "\n\nRoot: " << c;
|
||||
getch();
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#include<conio.h>
|
||||
#include<iostream.h>
|
||||
#include<math.h>
|
||||
#include <conio.h>
|
||||
#include <iostream.h>
|
||||
#include <math.h>
|
||||
float eq(float y)
|
||||
{
|
||||
return((3*y)-(cos(y))-2);
|
||||
return ((3 * y) - (cos(y)) - 2);
|
||||
}
|
||||
float eqd(float y)
|
||||
{
|
||||
return((0.5)*((cos(y))+2));
|
||||
return ((0.5) * ((cos(y)) + 2));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float y,x1,x2,x3,sum,s,a,f1,f2,gd;
|
||||
int i,n;
|
||||
float y, x1, x2, x3, sum, s, a, f1, f2, gd;
|
||||
int i, n;
|
||||
|
||||
clrscr();
|
||||
for(i=0;i<10;i++)
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
sum=eq(y);
|
||||
cout<<"value of equation at "<<i<<" "<<sum<<"\n";
|
||||
sum = eq(y);
|
||||
cout << "value of equation at " << i << " " << sum << "\n";
|
||||
y++;
|
||||
}
|
||||
cout<<"enter the x1->";
|
||||
cin>>x1;
|
||||
cout<<"enter the no iteration to perform->\n";
|
||||
cin>>n;
|
||||
cout << "enter the x1->";
|
||||
cin >> x1;
|
||||
cout << "enter the no iteration to perform->\n";
|
||||
cin >> n;
|
||||
|
||||
for(i=0;i<=n;i++)
|
||||
for (i = 0; i <= n; i++)
|
||||
{
|
||||
x2=eqd(x1);
|
||||
cout<<"\nenter the x2->"<<x2;
|
||||
x1=x2;
|
||||
x2 = eqd(x1);
|
||||
cout << "\nenter the x2->" << x2;
|
||||
x1 = x2;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
Reference in New Issue
Block a user