Cse Sample Question 4
Cse Sample Question 4
The Challenge:
On the day of the picnic, Omar Azraf gathers all the students and presents them with a
mysterious puzzle. He explains that they must work together to unravel a secret message
hidden within a set of tasks that involve various programming concepts. To succeed,
they must use their knowledge of functions, recursion, strings, and arrays to complete
each task.
a) In Task 1, the students are required to create a function that decodes scrambled words.
Describe the steps you would use to implement this function.
b) Task 4 involves function composition, where each student writes a function that
performs a specific operation and passes the result to the next student's function. How
would you ensure the correct order of function execution to obtain the final result?
c) Imagine that you were one of the students participating in this picnic-themed
programming challenge. Which task do you think would be the most challenging for you
personally, and why? How would you approach and tackle that specific task?
How many characters are there in the string ‘OpenAI’ in the following
code?
#include <stdio.h>
int main() {
char str[] = "OpenAI";
int count = 0;
while (str[count] != '\0') {
count++; }
printf("The length of the string is %d.\n", count);
return 0;
}
How many elements are there in the ‘numbers’ array in the following code?
#include <stdio.h>
int getArrayLength(int arr[]) {
int count = 0;
while (arr[count] != '\0') {
count++; }
return count; }
int main() {
int numbers[] = {2, 4, 6, 8, 10};
int length = getArrayLength(numbers);
printf("The length of the array is %d.\n", length);
return 0;
}
What is the output of the following code?
#include <stdio.h>
void printNumbers(int n) {
if (n <= 0) {
return;
}
printNumbers(n - 1);
printf("%d ", n);
}
int main() {
int num = 5;
printf("Numbers from 1 to %d: ", num);
printNumbers(num);
printf("\n");
return 0;
}