3/3/2003
Due date: 3/17/2003
12:30 PM
1. (10 points) Write a complete SAL program that accepts three angles of a triangle, x, y, and z as integer input and
determines whether the triangle is
· Equilateral : All angles are equal to 60 ( degrees )
· Isoceles: Two angles are equal
· Scalene: No angles are equal
and displays to the
user the type of the triangle as output.
2. (10 points) Write a complete SAL program that computes the sum of squares of first ‘n’ natural numbers. Do this in two methods in the same program and compare the results as shown below:
Method 1: Use an iterative loop to square each number
and add it to the sum.
Hint: The equivalent C++
code fragment:
sum = 0;
i = 1;
do
{
square = i * i;
sum = sum + square;
i++;
}
while ( i <= n );
Method 2: Use the following formula to compute the sum of squares of first ‘n’ natural numbers.
sum = ( n * (n +1) * ( 2n + 1) )/6;
Input accepted from the user :n
Output displayed to the user: sum
Instructions for submission:
1. Use SPIMSAL simulator to execute these programs.
2. Submit them by email to rvlhfb@umkc.edu before the due date.
3. Use the following subject line for the email: [cs282] Assignment 3
4. Please name the files as follows:(where firstname and lastname are your
first and last names)
<firstname_lastname_1.s> and <firstname_lastname_2.s>
5. You may discuss with your friends, but do not copy programs
from each other. Any cheating that is observed will mean 0 points for all the persons involved.