Center Of Gravity

C Program For Finding Center Of Gravity Source Code: #include<stdio.h> #include<conio.h> #include<string.h> #include<math.h> #include<stdlib.h> struct point { int x,y; }; void main() { int i,j,n,b,i1,j1; struct point s[30]; clrscr(); float t[20],m=0,k,k1,m1=0,p,h,t1[20]; printf("enter number of points:"); scanf("%d",&n); for(i=0;i<=n-1;i++) { printf("\nEnter x-part of point:"); scanf("%d",&s[i].x); printf("Enter y-part of point:"); scanf("%d",&s[i].y); } for(i=0;i<=n-1;i++) { m=0; for(j=0;j<=n-1;j++) { if(i!=j) { m=m+(float )sqrt(pow((s[i].x-s[j].x),2)+pow((s[i].y-s[j].y),2)); } } t[i]=m; printf("\nDistance for point %d=%f",i+1,m); } k=t[0]; for(i=0;i<=n-1;i++) { if(t[i]k1) k1=t1[j1]; } printf("\nMaximum distance from C.O.G.=%f",k1); getch(); } OUTPUT: enter number of points:5 Enter x-part of point:1 Enter y-part of point:2 Enter x-part of point:2 Enter y-part of point:1 Enter x-part of point:5 Enter y-part of point:-1 Enter x-part of point:1 Enter y-part of point:-5 Enter x-part of point:2 Enter y-part of point:-6 Distance for point 1=21.476471 Distance for point 2=18.102528 Distance for point 3=20.093359 Distance for point 4=20.153830 Distance for point 5=22.307423 C.O.G=(2,1) Maximum distance from C.O.G.=7.000000

Share:

0 comments