These are algorithms questions i need it to be in simple steps Question 1 You ne
ID: 667879 • Letter: T
Question
These are algorithms questions i need it to be in simple steps
Question 1 You need to decide whether the number 7 is a prime number or not. What steps do you take? Question 2 Now you are going to have to decide in some given number (not necessarily 7) is a prime number or not. What steps do you take? (Hint: You need to make your answer from Question 1 more general. How would you test if 11 is a prime number? What is different from when you tested 7?) Question 3 You are given a word, and need to decide if it is a palindrome or not. What steps do you take? Question 4 You have a stack of one thousand notecards, and each notecard has a number on it. You need to find the card with the highest number on it. What steps do you take? (Hint: Look through the cards and find the highest number. is not a solution. How do you determine which of two numbers is higher? How do you keep track of(i.e. store) the highest number you've found so far?)Explanation / Answer
START
SET N=7
FOR I = 2 TO 6
C=N MOD I
IF C=0 THEN
PRINT "NUMBER IS NOT PRIME"
BREAK THE LOOP
END IF
END FOR
IF I=N THEN
PRINT "NUMBER IS PRIME"
END IF
STOP
2.
START
PRINT "ENTER NUMBER"
INPUT N
FOR I = 2 TO N-1
C=N MOD I
IF C=0 THEN
PRINT "NUMBER IS NOT PRIME"
BREAK THE LOOP
END IF
END FOR
IF I=N THEN
PRINT "NUMBER IS PRIME"
END IF
STOP
3.
static bool IsPalindrome(string s)
{
bool palindrome = true;
for (int i = 0; i < s.Length / 2 + 1; i++)
{
if (s[i] != s[s.Length - i-1])
{
palindrome = false;
break;
}
}
return palindrome;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.