![photo](/responsive_image/150/150/0/0/0/cache/matlabcentral/profiles/18940122_1612353281918.jpg)
Mohammad Emaz Uddin
Followers: 0 Following: 0
Undergraduate student of Bangladesh University of Engineering and Technology on Department of Electrical and Electronic Engineering.
Feeds
已回答
Write a MATLAB script file that calculates the sum of first n natural numbers (the program could prompt the user for the number n). The program must use a “for” or “while” loop to accomplish this, and must NOT use the ready formula s = 1 2 n (n + 1).
clc; clear; close all; n= input('Enter numbers: '); sum=0; for i=1:1:n sum=sum+i; end disp (sum);
Write a MATLAB script file that calculates the sum of first n natural numbers (the program could prompt the user for the number n). The program must use a “for” or “while” loop to accomplish this, and must NOT use the ready formula s = 1 2 n (n + 1).
clc; clear; close all; n= input('Enter numbers: '); sum=0; for i=1:1:n sum=sum+i; end disp (sum);
3 years 前 | 0