mirror of
https://github.com/TheAlgorithms/C
synced 2025-02-16 21:44:16 +03:00
removed dependency on "conio.h"
This commit is contained in:
parent
8e7aa19113
commit
d7859b042c
@ -1,100 +1,104 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
void display(float a[20][20],int n)
|
||||
{
|
||||
int i,j;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<=n;j++)
|
||||
{
|
||||
printf("%.2f \t",a[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
float interchange(float m[20][20],int i,int n)
|
||||
{
|
||||
float tmp[20][20];
|
||||
float max=fabs(m[i][i]);
|
||||
int j,k=i;
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
for(j=i;j<n;j++)
|
||||
{
|
||||
if(max<fabs(m[j][i]))
|
||||
{
|
||||
max=fabs(m[j][i]);
|
||||
k=j;
|
||||
}
|
||||
}
|
||||
for(j=0;j<=n;j++)
|
||||
{
|
||||
tmp[i][j]=m[i][j];
|
||||
m[i][j]=m[k][j];
|
||||
m[k][j]=tmp[i][j];
|
||||
}
|
||||
return m[20][20];
|
||||
#define ARRAY_SIZE 20
|
||||
|
||||
void display(float a[ARRAY_SIZE][ARRAY_SIZE], int n)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
for (j = 0; j <= n; j++)
|
||||
{
|
||||
printf("%.2f \t", a[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
float eliminate(float m[20][20],int i,int n)
|
||||
|
||||
float interchange(float m[ARRAY_SIZE][ARRAY_SIZE], int i, int n)
|
||||
{
|
||||
float tmp[ARRAY_SIZE][ARRAY_SIZE];
|
||||
float max = fabs(m[i][i]);
|
||||
int j, k = i;
|
||||
|
||||
for (j = i; j < n; j++)
|
||||
{
|
||||
if (max < fabs(m[j][i]))
|
||||
{
|
||||
max = fabs(m[j][i]);
|
||||
k = j;
|
||||
}
|
||||
}
|
||||
for (j = 0; j <= n; j++)
|
||||
{
|
||||
tmp[i][j] = m[i][j];
|
||||
m[i][j] = m[k][j];
|
||||
m[k][j] = tmp[i][j];
|
||||
}
|
||||
return m[ARRAY_SIZE - 1][ARRAY_SIZE - 1];
|
||||
}
|
||||
float eliminate(float m[ARRAY_SIZE][ARRAY_SIZE], int i, int n)
|
||||
{
|
||||
float tmp;
|
||||
int k=1,l,j;
|
||||
for(j=i;j<n-1;j++)
|
||||
int k = 1, l, j;
|
||||
for (j = i; j < n - 1; j++)
|
||||
{
|
||||
tmp=-((m[i+k][i])/(m[i][i]));
|
||||
for(l=0;l<=n;l++)
|
||||
{
|
||||
m[i+k][l]=(m[i+k][l])+(m[i][l]*tmp);
|
||||
}
|
||||
k++;
|
||||
tmp = -((m[i + k][i]) / (m[i][i]));
|
||||
for (l = 0; l <= n; l++)
|
||||
{
|
||||
m[i + k][l] = (m[i + k][l]) + (m[i][l] * tmp);
|
||||
}
|
||||
k++;
|
||||
}
|
||||
return m[20][20];
|
||||
return m[ARRAY_SIZE - 1][ARRAY_SIZE - 1];
|
||||
}
|
||||
void main()
|
||||
int main(void)
|
||||
{
|
||||
int i,j,n,k=0,l;
|
||||
float m[20][20],mul,tmp[20][20],val,ans[20];
|
||||
clrscr();
|
||||
int i, j, n, k = 0, l;
|
||||
float m[ARRAY_SIZE][ARRAY_SIZE], mul, tmp[ARRAY_SIZE][ARRAY_SIZE], val, ans[ARRAY_SIZE];
|
||||
|
||||
printf("Total No.of Equations : ");
|
||||
scanf("%d",&n);
|
||||
printf("Total No.of Equations : ");
|
||||
scanf("%d", &n);
|
||||
|
||||
printf("\n");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("\n");
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
printf("Enter Co-efficient Of Equations %d & Total --->>>\n",i+1);
|
||||
for(j=0;j<=n;j++)
|
||||
{
|
||||
printf("r%d%d : ",i,j);
|
||||
scanf("%f",&m[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf(":::::::::::: Current Matrix ::::::::::::\n\n");
|
||||
display(m,n);
|
||||
printf("Enter Co-efficient Of Equations %d & Total --->>>\n", i + 1);
|
||||
for (j = 0; j <= n; j++)
|
||||
{
|
||||
printf("r%d%d : ", i, j);
|
||||
scanf("%f", &m[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf(":::::::::::: Current Matrix ::::::::::::\n\n");
|
||||
display(m, n);
|
||||
|
||||
for(i=0;i<n-1;i++)
|
||||
{
|
||||
printf("\n------->>>>>>>>>>>>>>>>>>>>>>>>-------- %d\n",i+1);
|
||||
m[20][20]=interchange(m,i,n);
|
||||
display(m,n);
|
||||
printf("\n_______________________________________\n");
|
||||
m[20][20]=eliminate(m,i,n);
|
||||
display(m,n);
|
||||
}
|
||||
printf("\n\n Values are : \n");
|
||||
for(i=n-1;i>=0;i--)
|
||||
{
|
||||
l=n-1;
|
||||
mul=0;
|
||||
for(j=0;j<k;j++)
|
||||
{
|
||||
mul=mul+m[i][l]*ans[l];
|
||||
l--;
|
||||
}
|
||||
k++;
|
||||
ans[i]=(m[i][n]-mul)/m[i][i];
|
||||
printf("X%d = %.2f\n",i+1,ans[i]);
|
||||
}
|
||||
getch();
|
||||
for (i = 0; i < n - 1; i++)
|
||||
{
|
||||
printf("\n------->>>>>>>>>>>>>>>>>>>>>>>>-------- %d\n", i + 1);
|
||||
m[ARRAY_SIZE - 1][ARRAY_SIZE - 1] = interchange(m, i, n);
|
||||
display(m, n);
|
||||
printf("\n_______________________________________\n");
|
||||
m[ARRAY_SIZE - 1][ARRAY_SIZE - 1] = eliminate(m, i, n);
|
||||
display(m, n);
|
||||
}
|
||||
printf("\n\n Values are : \n");
|
||||
for (i = n - 1; i >= 0; i--)
|
||||
{
|
||||
l = n - 1;
|
||||
mul = 0;
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
mul = mul + m[i][l] * ans[l];
|
||||
l--;
|
||||
}
|
||||
k++;
|
||||
ans[i] = (m[i][n] - mul) / m[i][i];
|
||||
printf("X%d = %.2f\n", i + 1, ans[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,46 +1,38 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
void main()
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define MAX_LEN INT_MAX
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int a[10],n,i,j,temp,sum=0;
|
||||
int a[MAX_LEN], n = 10, i, j, temp, sum = 0;
|
||||
float mean;
|
||||
clrscr();
|
||||
printf("Enter no. for Random Numbers :");
|
||||
scanf("%d",&n);
|
||||
for(i=0;i<n;i++)
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
a[i]=rand()%100;
|
||||
}
|
||||
printf("Random Numbers Generated are :\n");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("\nSorted Data:");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
n = atoi(argv[1]);
|
||||
if (n >= MAX_LEN)
|
||||
{
|
||||
if(a[i]<a[j])
|
||||
{
|
||||
temp=a[i];
|
||||
a[i]=a[j];
|
||||
a[j]=temp;
|
||||
}
|
||||
fprintf(stderr, "Maximum %d!\n", MAX_LEN);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
|
||||
printf("Random Numbers Generated are : ");
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
sum=sum+a[i];
|
||||
a[i] = rand() % 100;
|
||||
printf("%2d, ", a[i]);
|
||||
}
|
||||
mean=sum/(float)n;
|
||||
putchar('\n');
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
sum = sum + a[i];
|
||||
|
||||
mean = sum / (float)n;
|
||||
printf("\nMean :");
|
||||
printf("%f",mean);
|
||||
printf("%f", mean);
|
||||
|
||||
getch();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,50 +1,50 @@
|
||||
#include<stdio.h>
|
||||
//#include<conio.h>
|
||||
#include<math.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
void main()
|
||||
int main()
|
||||
{
|
||||
int a[10],n,i,j,temp;
|
||||
float mean,median;
|
||||
clrscr();
|
||||
int a[10], n, i, j, temp;
|
||||
float mean, median;
|
||||
|
||||
printf("Enter no. for Random Numbers :");
|
||||
scanf("%d",&n);
|
||||
for(i=0;i<n;i++)
|
||||
scanf("%d", &n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
a[i]=rand()%100;
|
||||
a[i] = rand() % 100;
|
||||
}
|
||||
printf("Random Numbers Generated are :\n");
|
||||
for(i=0;i<n;i++)
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
printf("\n%d", a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("\nSorted Data:");
|
||||
for(i=0;i<n;i++)
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if(a[i]<a[j])
|
||||
if (a[i] < a[j])
|
||||
{
|
||||
temp=a[i];
|
||||
a[i]=a[j];
|
||||
a[j]=temp;
|
||||
temp = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
printf("\n%d", a[i]);
|
||||
}
|
||||
|
||||
if(n%2==0)
|
||||
if (n % 2 == 0)
|
||||
{
|
||||
median=(a[n/2]+a[(n/2)-1])/2;
|
||||
median = (a[n / 2] + a[(n / 2) - 1]) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
median=a[n/2];
|
||||
median = a[n / 2];
|
||||
}
|
||||
printf("\nMedian is : %f",median);
|
||||
getch();
|
||||
printf("\nMedian is : %f", median);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,26 +1,27 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
void main()
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
float a,b,c,a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,x1,x2,x3;
|
||||
clrscr();
|
||||
float a, b, c, a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3, x1, x2, x3;
|
||||
|
||||
printf("Enter values of eq1:");
|
||||
scanf("%f%f%f%f",&a1,&a2,&a3,&d1);
|
||||
scanf("%f%f%f%f", &a1, &a2, &a3, &d1);
|
||||
printf("Enter values of eq2:");
|
||||
scanf("%f%f%f%f",&b1,&b2,&b3,&d2);
|
||||
scanf("%f%f%f%f", &b1, &b2, &b3, &d2);
|
||||
printf("Enter values of eq3:");
|
||||
scanf("%f%f%f%f",&c1,&c2,&c3,&d3);
|
||||
x1=x2=x3=0.0;
|
||||
scanf("%f%f%f%f", &c1, &c2, &c3, &d3);
|
||||
x1 = x2 = x3 = 0.0;
|
||||
do
|
||||
{
|
||||
a=x1;
|
||||
b=x2;
|
||||
c=x3;
|
||||
x1=(1/a1)*(d1-(a2*x2)-(a3*x3));
|
||||
x2=(1/b2)*(d2-(b1*x1)-(b3*x3));
|
||||
x3=(1/c3)*(d3-(c1*x1)-(c2*x2));
|
||||
}while(fabs(x1-a)>0.0001&&fabs(x2-b)>0.0001&&fabs(x3-c)>0.0001);
|
||||
printf("x1=%f\nx2=%f\nx3=%f",x1,x2,x3);
|
||||
getch();
|
||||
a = x1;
|
||||
b = x2;
|
||||
c = x3;
|
||||
x1 = (1 / a1) * (d1 - (a2 * x2) - (a3 * x3));
|
||||
x2 = (1 / b2) * (d2 - (b1 * x1) - (b3 * x3));
|
||||
x3 = (1 / c3) * (d3 - (c1 * x1) - (c2 * x2));
|
||||
} while (fabs(x1 - a) > 0.0001 && fabs(x2 - b) > 0.0001 && fabs(x3 - c) > 0.0001);
|
||||
printf("x1=%f\nx2=%f\nx3=%f", x1, x2, x3);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,45 +1,46 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
void main()
|
||||
{
|
||||
float x[20],y[20],a,sum,p;
|
||||
int n,i,j;
|
||||
clrscr();
|
||||
printf("Enter the no of entry to insert->");
|
||||
scanf("%d",&n);
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
int main()
|
||||
{
|
||||
float x[20], y[20], a, sum, p;
|
||||
int n, i, j;
|
||||
|
||||
printf("Enter the no of entry to insert->");
|
||||
scanf("%d", &n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
printf("enter the value of x%d->",i);
|
||||
scanf("%f",&x[i]);
|
||||
printf("enter the value of y%d->",i);
|
||||
scanf("%f",&y[i]);
|
||||
printf("enter the value of x%d->", i);
|
||||
scanf("%f", &x[i]);
|
||||
printf("enter the value of y%d->", i);
|
||||
scanf("%f", &y[i]);
|
||||
}
|
||||
printf("\n X \t\t Y \n");
|
||||
printf("----------------------------\n");
|
||||
for(i=0;i<n;i++)
|
||||
printf("----------------------------\n");
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
printf("%f\t", x[i]);
|
||||
printf("%f\n", y[i]);
|
||||
}
|
||||
printf("\nenter the value of x for interpolation:");
|
||||
scanf("%f", &a);
|
||||
sum = 0;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
p = 1.0;
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
printf("%f\t",x[i]);
|
||||
printf("%f\n",y[i]);
|
||||
}
|
||||
printf("\nenter the value of x for interpolation:");
|
||||
scanf("%f",&a)
|
||||
sum=0;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
p=1.0;
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
|
||||
if(i !=j)
|
||||
if (i != j)
|
||||
{
|
||||
p=p*(a-x[j])/(x[i]-x[j]);
|
||||
p = p * (a - x[j]) / (x[i] - x[j]);
|
||||
}
|
||||
sum=sum+y[i]*p;
|
||||
sum = sum + y[i] * p;
|
||||
}
|
||||
printf("ans is->%f",sum);
|
||||
getch();
|
||||
printf("ans is->%f", sum);
|
||||
|
||||
}}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,41 +1,41 @@
|
||||
#include<stdio.h>
|
||||
#include<math.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
float f(float x)
|
||||
float f(float x)
|
||||
{
|
||||
return 1.0+x*x*x; //This is the expresion of the function to integrate?
|
||||
return 1.0 + x * x * x; //This is the expresion of the function to integrate?
|
||||
}
|
||||
|
||||
void main()
|
||||
int main()
|
||||
{
|
||||
int i,n;
|
||||
float a,b,h,x,s2,s3,sum,integral;
|
||||
|
||||
int i, n;
|
||||
float a, b, h, x, s2, s3, sum, integral;
|
||||
|
||||
printf("enter the lower limit of the integration:");
|
||||
scanf("%f",&a);
|
||||
scanf("%f", &a);
|
||||
printf("enter the upper limit of the integration:");
|
||||
scanf("%f",&b);
|
||||
scanf("%f", &b);
|
||||
printf("enter the number of intervals:");
|
||||
scanf("%d",&n);
|
||||
|
||||
h=(b-a)/n;
|
||||
sum=f(a)+f(b);
|
||||
s2=s3=0.0;
|
||||
scanf("%d", &n);
|
||||
|
||||
for(i=1;i<n;i+=3)
|
||||
h = (b - a) / n;
|
||||
sum = f(a) + f(b);
|
||||
s2 = s3 = 0.0;
|
||||
|
||||
for (i = 1; i < n; i += 3)
|
||||
{
|
||||
x=a+i*h;
|
||||
s3=s3+f(x)+f(x+h);
|
||||
x = a + i * h;
|
||||
s3 = s3 + f(x) + f(x + h);
|
||||
}
|
||||
|
||||
for(i=3;i<n;i+=3)
|
||||
for (i = 3; i < n; i += 3)
|
||||
{
|
||||
x=a+i*h;
|
||||
s2=s2+f(x);
|
||||
x = a + i * h;
|
||||
s2 = s2 + f(x);
|
||||
}
|
||||
|
||||
integral=(h/3.0)*(sum+2*s2+4*s3);
|
||||
printf("\nValue of the integral = %9.4f\n",integral);
|
||||
|
||||
|
||||
integral = (h / 3.0) * (sum + 2 * s2 + 4 * s3);
|
||||
printf("\nValue of the integral = %9.4f\n", integral);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user