Post Test

Please answer the following problems to the best of your ability without any outside help. You can stop working on a problem after you worked on it for about five minutes without solving it.

Problems

Write the function char* upper_center(char* str) to return the passed string str with the middle character(s) in uppercase.

  • If str has an odd length, uppercase the middle character.

  • If str has an even length, uppercase the middle two characters.

  • If str has less than 3 characters then return str.

Example Input

Expected Output

upper_center('abc')

'aBc'

upper_center('abcd')

'aBCd'

upper_center('a')

'a'

Write a function int is_descending(int* nums) to do the following.

  • Return 1 if the numbers in the list nums are sorted in descending order.

  • Otherwise return 0.

  • If the list nums has less than two numbers in it return 1.

Example Input

Expected Output

is_descending({2,3,4})

0

is_descending({1})

1

is_descending({4,3,2})

1

Write the function int sum67(int* nums) that takes a list of numbers and returns the total of the numbers in the list except for all the numbers whose position is between a 6 and 7 in the list (inclusive).

Example Input

Expected Output

sum67({1,2})

3

sum67({2, 6, 8, 7, 2})

4

sum67({3, 6, 7})

3

Write the function int isAlmostPalindrome(char* x) that takes a string, x, and returns 1 if x can be a palindrome after deleting at most one character from it, and 0 otherwise. A string is a palindrome if the characters read the same backwards as forwards.

Example Input

Expected Output

isAlmostPalindrome("aba")

1

isAlmostPalindrome("abca")

1

isAlmostPalindrome("abc")

0

Feedback

Q-5: Please provide feedback here. Please share any comments, problems, or suggestions.

What to do next

Click on the following link to go to the post survey: Post Test

You have attempted of activities on this page