Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program: Thanks! Write a program that will read up to 100 circles. It

ID: 3675405 • Letter: W

Question

Write a C program:

Thanks!

Write a program that will read up to 100 circles. It is to compute the area of each circle and is to sort the circles by increasing areas. If two circles have the same area, the one whose centre is closest to the origin should come first in the sorted list. If two circles have the same area and their centres are at the same distance to the origin, they should appear in the sorted list in the order they were input. Your program is to use the point and circle typedefs from Problem 2. For circle, you should add an extra variable for the area. The circles are input as specified in Problems 2 so you should reuse the readCircle function (you can modify it if you find that convenient). NOTE: Your program is to actually sort the circles and not just print them in the specified order. You should write a function called circleSort to do this using either selection or bubble sort. Input: The circles will be entered one per line as three doubles. For example 2.3 4.5 6.2 is a circle centred at x=2.3 and y=4.5 with radius 6.2. The end of input is indicated by a line with a nonnumeric e.g. stop or end. There will be no more than 100 circles input and you can assume there are no errors in the input Output: The sorted list of circles is to be displayed with one circle per line. Each circle is to be displayed in the following format illustrated for the example circle above: c= (2.3000, 4.5000) r = 6.2000 a = 120.7628 You are responsible for making up your own test data to verify your program works correctly for all cases.

Explanation / Answer

/**Program to Sorted List of Circles**/

include<stdio.h>

include<math.h>

int main()

{

float PI=3.14, area[100],x[100],y[100],radius[100],swap[],d[100];

int i,j,n;

printf("Enter count of Circles:");

scanf("%d",n);

for(i=o;i<n;i++)

{

printf("Enter radius of %d circle: ",i+1);

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

printf("Enter values of x and y of %d circle: ");

scanf("%f %f", &x[i], &y[i]);

area[i]= PI*raddius*radius;

d[i]=sqrt(x2+y2);

}

for(i=0;i<n;i++)

{

for(j=0;j<n-c;j++)

{

if (area[j]>area[j+1])

{

swap[]= area[j];

area[j]= area[j+1];

area[j+1]= swap[];

swap[]= x[j];

x[j]= x[j+1];

x[j+1]=swap[];

swap[]=y[j];

y[j]=y[j+1];

y[j+1]=swap[];

}

if (area[j]=area[j+1])

{

if(d[j]>d[j+1])

{

swap[]= area[j];

area[j]= area[j+1];

area[j+1]= swap[];

swap[]= x[j];

x[j]= x[j+1];

x[j+1]=swap[];

swap[]=y[j];

y[j]=y[j+1];

y[j+1]=swap[];

}

}

}

}

printf("Sorted List of Circles ");

for(i=o;i<n;i++)

{

printf("c=(%f,%f) r= %f a= %f ",x[i],y[i],radius[i],area[i]);

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote