İ wrote a code but idk if its correct can u check it

1 view (last 30 days)
%First Program
pi=3;
kenar1=input('dikdörtgenin uzun kenarının boyunu giriniz: ');
Unable to run the 'fevalJSON' function because it calls the 'input' function, which is not supported for this product offering.
kenar2=input('dikdörtgenin yüksekliğini giriniz: ');
alan= kenar1*kenar2;
daire=pi*(kenar2/2)^2;
alan;
alan2=alan/2-daire;
disp(['Dikdörtgenin alanı: ',num2str(alan)])
disp(['Kırmızı bölgenin alanı: ',num2str(alan2)])

Answers (1)

Sam Chak
Sam Chak on 14 Mar 2024
The formulas are generally correct. However, there is a technical issue worth considering. Have you ever wondered why the area of the red region is 0 when the length is 3 and the height is 2?
There will be another issue after you fix it.
%First Program
pi = 3; % what is 'pie' 🥧?
side1 = 3; % input( 'Enter the length of the long side of the rectangle: ' );
side2 = 2; % input( 'Enter the height of the rectangle: ' );
area = side1*side2; % area of the rectangle
circle = pi*(side2/2)^2; % formula to calculate area of a perfect circle
area2 = area/2 - circle; % area of red region
disp(['Area of ​​the rectangle: ', num2str(area)])
Area of ​​the rectangle: 6
disp(['Area of ​​the red region: ', num2str(area2)])
Area of ​​the red region: 0

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!