İ wrote a code but idk if its correct can u check it
1 view (last 30 days)
Show older comments
%First Program
pi=3;
kenar1=input('dikdörtgenin uzun kenarının boyunu giriniz: ');
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)])
0 Comments
Answers (1)
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)])
disp(['Area of the red region: ', num2str(area2)])
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!