Solution 2: Algorithm 1

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.

Surya

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.

Share
Published by
Surya

Recent Posts

How to get the all the database and table sizes of MySQL or MariaDB?

If you are working with MySQL or MariaDB web server, sooner or later you will…

7 years ago

How to set or change default text editor for crontab in Linux?

To edit the crontab entries you use crontab -e. The command will check for the…

7 years ago

How to install Comodo SSL certificate with NGNIX web server?

Installation method for COMODO SSL Certificate If you have generated the CSR and purchased or…

7 years ago

How to give access to specific users to specific buckets on AWS S3

In AWS S3, you might want to provide the access to selected users to selected…

7 years ago

How to add or change the password (passphrase) of OpenSSH key?

It's possible you have earlier generated a ssh key without password/ passphrase. Later you found…

7 years ago

How to find files on linux OS ( distributions )

If you are working on Linux OS, finding files effectively always a tricky part. Like…

7 years ago