0% found this document useful (0 votes)
12 views2 pages

LAB3

The document outlines a MATLAB program for performing basic mathematical operations such as addition, subtraction, multiplication, and division. It prompts the user to select an operation and input two numbers, then calculates and displays the result. The program also includes error handling for invalid choices and division by zero.

Uploaded by

Hussein Raed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

LAB3

The document outlines a MATLAB program for performing basic mathematical operations such as addition, subtraction, multiplication, and division. It prompts the user to select an operation and input two numbers, then calculates and displays the result. The program also includes error handling for invalid choices and division by zero.

Uploaded by

Hussein Raed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Al-Mustaqbal University College

Department of Medical Instrumentation Techniques Engineering


Class: 1
Subject: Computer Programming and Applications
Lab Tutor: Hussein Shawki

clc;
clear;
disp('Choose a mathematical operation ')
disp('1. Addition (+)');
disp('2. Subtraction (-)');
disp('3. Multiplication (*)');
disp('4. Division (/)');
choice = input('(1-4)');
if choice < 1 || choice > 4
disp('Enter a number between 1 and 4');
else
% ‫ادخال الرقم األول والرقم الثاني‬
num1 = input('Enter the first number ');
num2 = input('Enter the second number ');

% ‫اجراء العلميات الحسابية‬


switch choice
case 1
result = num1 + num2;
operator = '+';
case 2
result = num1 - num2;
operator = '-';
case 3
result = num1 * num2;
operator = '*';
case 4
% ‫التحقق هل المقام صفر ام ال‬
if num2 == 0
disp('‫;)'اليمكن القسمة على صفر‬
return;
end
result = num1 / num2;
operator = '/';
end
Al-Mustaqbal University College
Department of Medical Instrumentation Techniques Engineering
Class: 1
Subject: Computer Programming and Applications
Lab Tutor: Hussein Shawki

% ‫طباعة الناتج‬
fprintf('result: %.2f %s %.2f = %.2f\n', num1,
operator, num2, result);n
end

You might also like