subject

The following C program reads an integer number x from the keyboard and prints whether it is a prime number. The program starts by assuming that x is prime. Then, it checks whether the number is divisible by each integer between 2 and x / 2, by checking whether the remainder of that division is 0. If so, the program immediately concludes that x is not prime. #include
int main()
{
int x;

printf("Enter number: ");
scanf("%d", &x);
// Assume prime
int is_prime = 1;
// Traverse
for (int i = 2; i <= x / 2; i++)
{
if (x % i == 0)

{
is_prime = 0;
break; }

}

// Result
if (is_prime)
printf("Prime number\n");
else
printf("Not a prime number\n");
// End

return 0; }

Required:
Write a MIPS program that reproduces the exact behavior of the given C code.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:30
Some of the first computer games were created in the early 1970s by college students experimenting after hours to see what the were capable of doing.
Answers: 3
question
Computers and Technology, 24.06.2019 11:30
Convert 11001110(acdd notation) into decimal
Answers: 2
question
Computers and Technology, 24.06.2019 16:00
To fill (copy) a cell across or down, point to the of the cell and drag. top left corner top right corner bottom left corner bottom right corner
Answers: 3
question
Computers and Technology, 24.06.2019 23:30
True or false when a host gets an ip address from a dhcp server it is said to be configured manually
Answers: 1
You know the right answer?
The following C program reads an integer number x from the keyboard and prints whether it is a prime...
Questions
Questions on the website: 13722360