%% Problem 1
fprintf('Problem 1:\r') % I used '\r' to go to next line
fprintf('Hanieh Mazloom Farsibaf\r\r')

%% Problem 2
fprintf('Problem 2:\r')
Sum=0;                  % Sum is used to sum over 1:100
for ii=1:100
    Sum=ii+Sum;
end
fprintf('The summation of integer numbers from 1 to 100 is = %d\r\r',Sum)

%% Problem 3 Method one
%Number of prime numbers to find
%It's better to use a variable than to 'hard code' a number everywhere in
%the code
fprintf('Problem 3:\r')
fprintf('The first ten prime numbers are = \r ')
fprintf('Method one\r')

Nmax=10;

%make an empty array to hold the first
primes=zeros(1,Nmax);

%Counter for number we have found
Nprime=0;

%Our current integer to be tested
Ntest=2;

while Nprime<Nmax %don't stop until we find Nmax primes
    
    %set a flag 
    notPrime=0;
    for ii=2:Ntest-1 %test all integers up to Ntest-1 (we could also just go to sqrt(Ntest))
        if Ntest/ii==round(Ntest/ii)
            notPrime=1; %This means it is not a prime
        end
    end
    
    if notPrime==0 %this means it 'survived' the division test of all integers
        Nprime=Nprime+1;    %we found another, so increment our counter
        primes(Nprime)=Ntest; %put our found prime into the array
    end

    Ntest=Ntest+1; %increment the integer that we will test 
end

primes

%% Problem 3 Method two
fprintf('Method two\r')

Ncount=1;    % The number of prime numbers we need
Ntest=2;     % Specific number starts from 2 and we test it if it is prime 
             % or not.
while Ncount <10
    j=0;     % I use it to count the denominatpor of Ntest
    for ii=1:Ntest
        if mod(Ntest,ii)==0 % By this condition ii is denominator of Ntest
            j=j+1;
        end
    end 
    if j==2
%         display(N);
        primes(Ncount)=Ntest; % primes is a matirx includes prime numbers.
        Ncount=Ncount+1;   
        %N=N+1;
    else 
      %  N=N+1;
    end
    Ntest=Ntest+1;
end 

primes



%% probelm 4
fprintf('Problem 4:\r')
fprintf('Look at the figure.\r\r')

X=0:.1:20;
Y=sin(X);
plot(X,Y,'r','LineStyle','--','linewidth',4)
% You can add this option for plot
% 'Color', [,,] (1,3)matrix
% 'LineStyle','--' Or ,'-.', ... many examples!
% 'Marker','o','*', ...
% 'MarkerEdgeColor', [,,]  Check help/plot to get more ...
xlabel('X','fontsize',20)
ylabel('Sin(X)')
title('Hanieh Mazloom Farsibaf','fontsize',15)
legend('Sin(X)')

%% Probem 5
fprintf('Problem 5:\r')

X=[1 2 3; 4 5 6;7 8 9]

%% Problem 5 

X(3,2)=18            % I just change one element of above matrix X
                     % You can also use X(6) but it is not recommended.
%% Problem 7
fprintf('Problem 7:\r')
Squ=HW1_Solution_CalSquare(10.5); % I made a function by the name of HW1_Solution_CalSquare to calculate
                     % the sqaure of any number. 
fprintf('The square of 10.5 is = %d\r',Squ)


