1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Thai dinh chinh DE170147 lap 05

5 2 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 260,67 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 1

USE SIMPLE MENU TO MANAGE PROGRAM FUNCTIONS

THAI DINH CHINH - DE170147

CSI201- Lap W5

Trang 2

Quadratic 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 3

Bank 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 4

Main 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 5

Thank You <3

Ngày đăng: 25/10/2022, 14:09

w