Program:
#include<stdio.h>
#include<math.h>
void main()
{
int n, I, j, k;
float sumx, sumxsq, sumy, sumxy, x, y;
float sumx3, sumx4, sumxsqy, a[20][20],u=0.0,b[20];
printf(“\n Enter the n value”);
scanf(“%d”, &n); sumx = 0; sumxsq = 0; sumy = 0; sumxy = 0; sumx3 = 0; sumx4 = 0; sumxsqy = 0; for(i=0; i<n; i++)
{
scanf(“%f %f”, &x, &y); sumx +=x;
sumxsq += pow(x,2); sumx3 += pow(x,3); sumx4 += pow(x,4); sumy +=y;
sumxy += x * y;
sumxsqy += pow(x,2) *y;
}
a[0][0] = n;
a[0][1] = sumx; a[0][2] = sumxsq; a[0][3] = sumy; a[1][0] = sumx; a[1][1] = sumxsq; a[1][2] = sumx3; a[1][3] = sumxy; a[2][0] = sumxsq; a[2][1] = sumx3; a[2][2] = sumx4; a[2][3] = sumxsqy;
for(i=0; i<3; i++)
{
for(j=0; j<=3; j++) printf(“%10.2f”,a[i][j]);
printf(“\n”);
}
for(k=0; k<=2; k++)
{
for(i=0;i<=2;i++)
{
If(i!=k)
u=a[i][k]/a[k][k]; for(j = k; j<=3; j++)
a[i][j]=a[i][j] – u * a[k][j];
}
}
for(i=0;i<3;i++)
{
[i] = a[i][3]/a[i][i]; printf(“\nx[%d] = %f”, I, b[i]);
}
printf(“\n”);
printf(“y= %10.4fx +10.4 fx +%10.4f”,b[2],b[i],b[0]);
}
Input/Output:
Enter the n value 10
-4 21
-3 12
-2 4
-1 1
0 2
1 7
2 15
3 30
4 45
5 67
10.00 5.00 85.00 204.00
5.00 85.00 125.00 513.00
85.00 125.00 1333.00 3193.00
X[0] = 2.030303
X[1] = 2.996970
X[2] = 1.984848
Y = 1.9848xsq + 2.9979x + 2.0303
VIVA QUESTIONS
1) Define insertion sort ?
Ans: Insertion sort is similar to playing cards. To sort the cards in yourhand you extrat a card shift the remaining cards and then insert the extracted card in its correct place.
2) Efficiency of the insertion sort ?
Ans: The efficiency of insertion sort is O(n2).
1) Define insertion sort ?
Ans: Insertion sort is similar to playing cards. To sort the cards in yourhand you extrat a card shift the remaining cards and then insert the extracted card in its correct place.
2) Efficiency of the insertion sort ?
Ans: The efficiency of insertion sort is O(n2).
No comments:
Post a Comment