Sei sulla pagina 1di 13

CE793

1. (a) NEWTON RAPHSON METHOD

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float s,n,q,b,m,err,y,a,P,R,T,yn=0,Fy=0,dFy=0,A;
printf("Enter the discharge: ");
scanf("%f",&q);
printf("Enter the side slope: ");
scanf("%f",&s);
printf("Enter the manning's rugosity co-efficient: ");
scanf("%f",&n);
printf("Enter the bottom width of the channel: ");
scanf("%f",&b);
printf("Enter the bed slope of the channel: ");
scanf("%f",&m);
printf("Enter the permissible error: ");
scanf("%f",&err);
printf("Enter the trial depth: ");
scanf("%f",&y);
a=y;
yn=0;
while(fabs(y-yn)>err)
{
y=a;
A=(float)((b*y)+(m*pow(y,2)));
P=(float)(b+(2*y*sqrt((m*m)+1)));
Page | 1

CE793

R=A/P;
T=(float)((b+(2*m*y)));
Fy=(float)(((pow(a,(5/3))*sqrt(s))/(n*pow(P,(2/3))))-q);
dFy=(float)((sqrt(s)/n)*(((5/3)*pow(R,(2/3))*T)((4/3)*pow(R,(5/3))*sqrt((m*m)+1))));
yn=(float)(y-(Fy/dFy));
a=yn;
}
printf("The normal depth of the channel is %f m",y);
getch();
}

Page | 2

CE793

1. (b) NEWTON RAPHSON METHOD

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float f1,f,Re,r, Ff,dFf,e;
printf("Enter the reynolds no. : ");
scanf("%f",&Re);
printf("Enter the first trial value of f: ");
scanf("%f",&f);
printf("Enter the error limit: ");
scanf("%f",&e);
do
{
f1=f;
Ff= (float) ((2*log10(Re*pow(f,.5)))-0.8-(1/pow(f,.5)));
dFf= (float) ((0.434/f)+(1/(2*pow(f,(1.5)))));
f=f-(Ff/dFf);
r= (f-f1)/f1;

}while(fabs(r)>e);

printf("The friction factor is %f \n",f);


getch();
}

Page | 3

CE793

2. GAUGE DISCHARGE

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a=7.5,sX=0,sY=0,sXY=0,sX2=0,sY2=0,sYY=0,beta,b,Cr,h1,Q1,r,r1,r2;
float Q[15],h[15],X[15],Y[15],t[15];
int i,N;
printf("\nEnter the number of gauge readings and discharge: ");
scanf("%d",&N);
printf("\nEnter the gauge reading in m: ");
for(i=0;i<N;i++)
{

scanf("%f",&h[i]);
}
printf("\nEnter the gauge discharge in cubic metre per sec: ");
for(i=0;i<N;i++)
{

scanf("%f",&Q[i]);
}

for(i=0;i<N;i++)
{
t[i]=(float)(h[i]-a);
Page | 4

CE793

X[i]=(float)(log10(t[i]));
Y[i]=(float)(log10(Q[i]));
}
for(i=0;i<N;i++)
{
sX=(float)(sX+X[i]);
sY=(float)(sY+Y[i]);
sX2=(float)(sX2+(X[i]*X[i]));
sY2=(float)(sY2+(Y[i]*Y[i]));
sXY=(float)(sXY+(X[i]*Y[i]));
}
printf("\nsX %f",sX);
printf("\nsY %f",sY);
printf("\nsX2 %f",sX2);
printf("\nsXY %f",sXY);
printf("\nsY2 %f",sY2);
r1=(float)((N*sXY)-(sX*sY));
printf("\nr1: %f",r1);
r2=(float)(sqrt(((N*sX2)-pow(sX,2))*((N*sY2)-pow(sY,2))));
printf("\nr2: %f",r2);
r=(float)(r1/r2);
printf("\nThe value of correlation coefficient is: %f",r);
beta=(float)((N*sXY-sX*sY)/(N*sX2-sX*sX));
printf("\nbeta: %f",beta);
b=(float)((sY-beta*sX)/N);
printf("\nb: %f",b);
Cr=(float)(pow(10,b));
printf("\nCr= %f",Cr);

Page | 5

CE793

printf("\nEnter the gauge reading at which discharge is required: ");


scanf("%f",&h1);
Q1=(float)((Cr*pow((h1-a),beta)));
printf("\nThe value of discharge at the gauge reading is: %f cubic metre per sec",Q1);
getch();
}

Page | 6

CE793

3. GAUSS ELIMINATION METHOD

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
float a[3][4],x[3],sum,temp;
printf("\nEnter the percentage of sand, fine gravel and coarse gravel of three different
sources and the engineer needs\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<=3;j++)
scanf("%f",&a[i][j]);
}
for(i=0;i<2;i++)
{
for(j=i+1;j<3;j++)
{
temp=0.0;
temp=(float)(a[j][i]/a[i][i]);
for(k=i;k<=3;k++)
{
a[j][k]=(float)(a[j][k]-(temp*a[i][k]));
}
}
}
printf("\nMatrix after calculation is:\n \n");

Page | 7

CE793

for(i=0;i<3;i++)
{
for(j=0;j<=3;j++)
printf("%f\t",a[i][j]);
printf("\n");
}
x[2]=(float)(a[2][3]/a[2][2]);
for(i=1;i>=0;i--)
{
sum=0.0;
for(j=i+1;j<3;j++)
{
sum=(float)(sum+(a[i][j]*x[j]));
}
x[i]=(float)((a[i][3]-sum)/a[i][i]);
}
printf("\n Solution of the equations is:\n \n");
for(i=0;i<3;i++)
{
printf("x[%d] = %f\n",i,x[i]);
}
getch();
}

Page | 8

CE793

4. TRAPEZOIDAL METHOD

#include <stdio.h>
#include <math.h>
#include <conio.h>
void main ()
{
int x[9],y[9],i=0,h=0,s=0,a=0,n=0;
printf("Enter the number of depths \n");
scanf("%d",&n);
printf("Enter the values of X \n");
for(i=0;i<n;i++)
{
scanf("%d",&x[i]);
}
printf("Enter the values of Y\n");
for(i=0;i<n;i++)
{
scanf("%d",&y[i]);
}
h= x[1]-x[0];
for(i=1;i<n-1;i++)
{
s=s+ y[i];
}
a= (h/2)*(y[0]+y[n-1]+(2*s));
printf("Area is %d \n", a);
}
Page | 9

CE793

5. BOD CONCENTRATION

#include <stdio.h>
#include <conio.h>
void main()
{
float f(float B,float Kd);
float g(float B,float Kd,float D,float Ka);
float B,t,dB,dD,D,Kd,Ka,n1;
int i,n;
printf("\nEnter the initial BOD concentration at the beginning: ");
scanf("%f",&B);
printf("\nEnter the Deoxygenation rate constant: ");
scanf("%f",&Kd);
printf("\nEnter the initial DO deficit: ");
scanf("%f",&D);
printf("\nEnter the Reaeration rate constant: ");
scanf("%f",&Ka);
printf("\nEnter the time interval: ");
scanf("%f",&t);
printf("\nEnter the day at which BOD & DO deficit is required: ");
scanf("%d",&n);
n1=(float)(n/t);
for(i=1;i<=n1;i++)
{
dB=(float)(t*f(B,Kd));
dD=(float)(t*g(B,Kd,D,Ka));
B=(float)(B+dB);
Page | 10

CE793

D=(float)(D+dD);
printf("\n%d\t%f\t%f",i,B,D);
}

printf("\n\nValue of B & DO deficit at t=%d days is %f mg/L & %f mg/L


respectively",n,B,D);
getch();
}
float f(float B,float Kd)
{
return((float)(-Kd*B));
}
float g(float B,float Kd,float D,float Ka)
{
return((float)((Ka*D)-(Kd*B)));
}

Page | 11

CE793

6. GAUSS SEIDEL METHOD

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a[10][10],x[10],sum,e,temp=0.0,err;
int m,i,j;
printf("\n Enter the number of unknown: ");
scanf("%d", &m);
printf("\n Enter the coefficients: \n");
for(i= 0;i<m;i++)
{
for(j=0;j<=m;j++)
{
scanf("%f", &a[i][j]);
}
}
printf("\n Enter the error limit: ");
scanf("%f", &e);
for(i=0;i<m;i++)
{
x[i]=0.0;
}
do
{

Page | 12

CE793

for(i=0;i<m;i++)
{
sum=0;

for(j=0;j<m;j++)
{
if(j!=i)
{
sum=sum+(a[i][j]*x[j]);
}
}
temp=(a[i][m]-sum)/a[i][i];
err= (float)fabs((temp-x[i]));
x[i]=temp;
}

}while(err>e);

printf("\n The result is");


for(i=0;i<m;i++)
printf("\n x[%d]= %f",i+1,x[i]);

getch();
}

Page | 13

Potrebbero piacerti anche