# Answered! A positive integer which is only divisible by 1 and itself is a prime number. Write a program to determine whether a…

Don't use plagiarized sources. Get Your Custom Essay on
Answered! A positive integer which is only divisible by 1 and itself is a prime number. Write a program to determine whether a…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

A positive integer which is only divisible by 1 and itself is a prime number. Write a program to determine whether a positive integer, n, is prime and the worst-case running time of your program should be O(y/n). Please determine the running time of merge sort (a) sorted input (b) reverse-ordered input (c) random input

#include <stdio.h>

int main()
{
int number, i, flag = 0;

printf(“Enter a positive integer: “);
scanf(“%d”,&number);

for(i=2; i<=number/2; ++i)
{
if(number%i==0)
{
flag=1;
break;
}
}

if (flag==0)
printf(“%d is a prime number.”,number);
else
printf(“%d is not a prime number.”,number);

return 0;
}

For given scenarios running time depends on implementation. When they are naively implemented, merge sort indeed uses O(n * log n) time.

Ans:  O(n * log n) for all three scenarios.