Thai Dinh Chinh DE170147 Lap Week 5 USE SIMPLE MENU TO MANAGE PROGRAM FUNCTIONS THAI DINH CHINH DE170147 CSI201 Lap W5 Quadratic equation Start Read a, b, and c values Compute d = b2 4ac if d > 0 then.
Trang 1USE SIMPLE MENU TO MANAGE PROGRAM FUNCTIONS
THAI DINH CHINH - DE170147
CSI201- Lap W5
Trang 2Quadratic equation
Start
Read a, b, and c values
Compute d = b2 4ac
if d > 0 then
r1 = b+ sqrt (d)/(2*a)
r2 = b sqrt(d)/(2*a)
Otherwise if d = 0 then
compute r1 = -b/2a, compute r2=-b/2a print r1,r2 values Otherwise if d < 0 then print
roots are imaginary
Stop
Trang 3Bank deposit problem
Star
Read the amount
Read years(months)
Read rate.
Calculate the interest with the
formula:
"Interest=Amount*Years*Rate/100
Print interest.
Trang 4Main codes
Quadratic equation:
float a, b, c, d, r1, r2;
printf(" Enter a, b and c where a*x*x + b*x + c = 0: ");
scanf("%f %f %f", &a, &b, &c);
d = b*b - 4*a*c;
if( d>=0){
r1 = (float) ((-b + sqrt(d)) / (2*a));
r2 = (float) ((-b - sqrt(d)) / (2*a));
printf(" The real roots: r1 = %.2f, r2 = %.2f", r1, r2);
}
else printf(" Roots are imaginary");
}
Bank deposit problem:
float D,r,m,A;
BG:
printf("\n Amount to be deposit in the bank (positive number): ");
scanf("%f",&D);
printf("\n Enter the rate of interest per year (a positive number <= 0.1): "); scanf("%f",&r);
printf("\n How many months you want to deposit (a positive number): "); scanf("%f",&m);
if (D>0 && r>0 && r<=0.1 && m>0){
A = D + D*r*m/12;
printf("\n Amount after %0.1f months with interest is: %0.2f\n",m,A);
} else{
printf("\n Invalid input, try again !\n");
goto BG;
}
Trang 5Thank You <3