All Sorting Program

All Sorting In one Programs using Function ..


[cpp]

#include <stdio.h>
#include <conio.h>
#define n 5
void main()
{
int i,j,k,z,t,temp;
float x[n],y[n][n],yofx,u,h,ans,uu,fact;

printf("\nHow many elements do you want to enter? : ");
scanf("%d",&i);
z=i;
for(k=0;k<=i-1;k++)
{
printf("\nEnter value of X[%d] : ",k+1);
scanf("%f",&x[k]);
printf("\nEnter value of Y[%d] : ",k+1);
scanf("%f",&y[k][0]);
}
printf("\n\t\tEnter value of x for calculate y : ");
scanf("%f",&yofx);
//Table
for(j=1;j<=i-1;j++)
{
for(k=0;k<=z-2;k++)
{
y[k][j]=y[k+1][j-1]-y[k][j-1];
}
z–;
}
//print the table
z=i;
printf("\ni xi\t yi");
for(t=0;t<i-1;t++)
{
printf(" D%dyi", t+1);
}
printf("\n");
printf("\n—————————————————-\n");
for(j=0;j<=i-1;j++)
{
printf("%d %f ",j+1,x[j]);
for(k=0;k<=z-1;k++)
{
printf("%.1f ",y[j][k]);
}
printf("\n");
z–;
}
//Calculation
temp=0;
for(j=0;j<i-1;j++)
{
if(yofx>x[j])
{
temp=temp+1;
}
}
temp=temp-1; //For select the above raw
h=x[1]-x[0]; //h=x2-x1
u=float(yofx-x[temp])/h; //u=(x-x1)/h
ans=y[temp][0];
uu=1;
fact=1;
for(j=1;j<=i-temp-1;j++)
{
for(k=1;k<=j;k++)
{
fact=fact*k;
uu=(uu*(u-(k-1)));
}
ans=ans+(y[temp][j]*uu)/fact;
uu=1;
fact=1;
}
printf("\n\n\tAnswer : : : %f",ans);
getch();
}

[/cpp]

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.