In: Computer Science
Write assembly instructions that compute the following:
All of the statements above should print the answers using print_int
MUST BE IN ASSEMBLY LANGUAGE PLEASE
1. The
sum of all even numbers between 2 and 100 (inclusive)?
public static void main(String[] args) {
int number = 1;
int sum = 0;
while (number >= 2 && number <= 100){
if (number % 2 == 0)
sum =
number + sum;
number ++;
}
System.out.println("The sum of all positive numbers is: " +
sum);
}
}
2.
sum of two numbers A and B
:public
class ComputeSumAAndB
{
public
static void main (String[] args)
{
Scanner in = new
Scanner(System.in);
System.out.print("Please enter
2 integers: "); //prompts user for ints
int a = in.nextInt();
int b = in.nextInt();
int sum = 0;
for (int j = a; j <= b; j++)
{
if (j
% 2 == 1)
sum += j;
}
System.out.println("The sum of
all odd numbers (inclusive) between " + a + " and "+ b + " is " +
sum);
}
}
----------------------------
The sum of all the squares between 1 and 100 (inclusive)
int n =
1;
int squareValue;
int sum = 0;
while (n <= 10) {
squareValue= (n*n);
sum += squareValue;
n++;
}
System.out.println(sum);
1. The
sum of all even numbers between 2 and 100 (inclusive)?
public static void main(String[] args) {
int number = 1;
int sum = 0;
while (number >= 2 && number <= 100){
if (number % 2 == 0)
sum =
number + sum;
number ++;
}
System.out.println("The sum of all positive numbers is: " +
sum);
}
}
2.
sum of two numbers A and B
:public
class ComputeSumAAndB
{
public
static void main (String[] args)
{
Scanner in = new
Scanner(System.in);
System.out.print("Please enter
2 integers: "); //prompts user for ints
int a = in.nextInt();
int b = in.nextInt();
int sum = 0;
for (int j = a; j <= b; j++)
{
if (j
% 2 == 1)
sum += j;
}
System.out.println("The sum of
all odd numbers (inclusive) between " + a + " and "+ b + " is " +
sum);
}
}
----------------------------
The sum of all the squares between 1 and 100 (inclusive)
int n =
1;
int squareValue;
int sum = 0;
while (n <= 10) {
squareValue= (n*n);
sum += squareValue;
n++;
}
System.out.println(sum);