Tải bản đầy đủ (.pdf) (5 trang)

Thai dinh chinh DE170147 lap 05

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (260.67 KB, 5 trang )

CSI201- Lap W5
USE SIMPLE MENU TO
MANAGE PROGRAM
FUNCTIONS.
THAI DINH CHINH - DE170147


Quadratic equation
Design (Algorithm)
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

Flowchart


Bank deposit problem
Design (Algorithm)
Star
Read the amount
Read years(months)


Read rate.
Calculate the interest with the
formula:
"Interest=Amount*Years*Rate/100
Print interest.

Flowchart


Main codes
Quadratic equation:
Bank deposit problem:
float a, b, c, d, r1, r2;
float D,r,m,A;
printf(" Enter a, b and c where a*x*x + b*x + c = 0: "); BG:
scanf("%f %f %f", &a, &b, &c);
printf("\n Amount to be deposit in the bank (positive number): ");
d = b*b - 4*a*c;
scanf("%f",&D);
if( d>=0){
printf("\n Enter the rate of interest per year (a positive number <= 0.1): ");
r1 = (float) ((-b + sqrt(d)) / (2*a));
scanf("%f",&r);
r2 = (float) ((-b - sqrt(d)) / (2*a));
printf("\n How many months you want to deposit (a positive number): ");
printf(" The real roots: r1 = %.2f, r2 = %.2f", r1, r2);
scanf("%f",&m);
}
if (D>0 && r>0 && r<=0.1 && m>0){
else printf(" Roots are imaginary");

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;
}


Thank You <3



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×