Solution 2: Algorithm 1

Algorithm
Algorithm

Below is the solution for Algorithm Problem 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define PI 3.14159265358979323846

float compute_comman_area(double r0,double r1,double x0,double y0,double x1,double y1){

     double c,CBA,CAB,CBD,CAD,Area;

     //length
     c = sqrt(pow((x1-x0),2) + pow((y1-y0),2));

     //IN RADIANS
     CBA = (acos((pow(r1,2) + pow(c,2) - pow(r0,2))/(2*r1*c)));
     CAB = (acos((pow(r0,2) + pow(c,2) - pow(r1,2))/(2*r0*c)));

     CBD = 2*CBA;
     CAD = 2*CAB;

     Area = (CBD*pow(r1,2) - pow(r1,2)*sin(CBD) + CAD*pow(r0,2) - pow(r0,2)*sin(CAD))/2;

     printf("%lf", CBA);

     return Area;
}

int main(){

    double r1=10,r0=10,x0=0,y0=0,x1=0,y1=10, Area, Area0;

    //getting input
    /*printf("Enter the radius of the first circle\nand the centre point");
    scanf("%lf%lf%lf",&r0,&x0,&y0);
    printf("Enter the radius of the first circle\nand the centre point");
    scanf("%lf%lf%lf",&r1,&x1,&y1);*/

    //calling function to compute area
    Area0 = PI * pow(r0, 2) + PI * pow(r1, 2);
    Area = Area0 - compute_comman_area(r0,r1,x0,y0,x1,y1);

    //printing the area
    printf("The area thus computed is:%lf",Area);

return 0;
}

You can download the source file here.

Living in permanent beta mode: Learning, Improving & evolving. SPECIALTIES: Web Application Development, Digital Media, E-Commerce Solutions, SEO, CRM Solutions, Open Source Technologies, System Administration ( Linux ), VOIP Solutions, Cloud Computing, Web Security.

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Site Footer