What’s the problem of my code? Please help…
#include<stdio.h>
#define pi 3.14159265359
int main()
{
int a,r1,r2,r3,r4,C;
double sq_area,cir_area,result;
do{
scanf("%d %d %d %d %d",&a,&r1,&r2,&r3,&r4);
sq_area=a*a;
cir_area=pi*(r1*r1+r2*r2+r3*r3+r4*r4)/4;
result=sq_area-cir_area;
printf("%.3lf\n",result);
C=getchar();
}
while(C!=EOF);
return 0;
}
#include<stdio.h>
#include <math.h>
int main()
{
double a,r1,r2,r3,r4,area;
while(scanf("%lf %lf %lf %lf %lf",&a,&r1,&r2,&r3,&r4)!=EOF){
if((r1+r2)<=a && (r3+r4)<=a)
{
area=a*a-acos(0.-1)/4*(r1*r1+r2*r2+r3*r3+r4*r4);
printf("%0.3lf\n",area);
}
}
return 0;
}
Either my coding or your instruction is right .So where is going wrong though all the statements indicate the same?please notice…
Wrong answer on test 2
Can anyone help me?
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
float a, r1, r2, r3, r4, ans;
while (cin >> a >> r1 >> r2 >> r3 >> r4 ) {
ans = pow(a, 2) - (pow(r1, 2) + pow(r2, 2) + pow(r3, 2) +pow(r4, 2))*acos(-1)/4;
cout << fixed << setprecision(3) << ans << endl;
}
return 0;
}