原始问题:
编写matlab脚本exam03a.m,实现功能
Matlab脚本exam03a.m的功能是计算两个给定的数字之间所有整数的和。
以下是matlab脚本exam03a.m的代码:
% exam03a.m
% This program calculates the sum of all integers between two given numbers
% Define variables:
n1 = input('Enter the first number: '); % prompt user to enter the first number
n2 = input('Enter the second number: '); % prompt user to enter the second number
total = 0; % initialize total to 0
if n1 > n2 % check if n1 is greater than n2, if so swap them around
temp = n1; % store n1 in a temporary variable
n1 = n2; % assign value of n2 to n1 . . . . . . . . .. .. .. .. .. ... ... ... ... .... .... .... .... ...... ...... ...... ...... ........ ........ ........ ........ .......... .......... .......... ............ ............ ............ .............. .............. .............. ................ ................ ................ ................ .............. .............. .............. .................. .................. .................. ................... ................... ................... ....................
Prev:《你究竟是谁》