Question: Hey, could I get some help with this? Language is C. I've already answered most of these but I want to double check my work.
Hey, could I get some help with this? Language is C. I've already answered most of these but I want to double check my work. Please give detailed responses and explain how it works. Thank you.
1. True or False:
a) In a recursion function the base case could be empty. [TRUE/FALSE]
b) Usually recursion is less efficient in terms of both execution speed and memory usage compared to iteration. [TRUE/FALSE]
2. What does the following recursive function do? It performs a mathematical operation. You are to identify the operation. What will be the value of result if a = 10, b= 4?
int Find(int b, int a)
// Precondition: a is assigned and a > 0
// b is assigned and b >= 0
{
if (b < a) // Base case
return 0;
else // General case
return (1 + Find (b - a, a));
}
3. What will be the output of the following program:
#include
int main()
{
int array[]={45, 67, 89};
int *array_ptr = &array[1];
printf("%i ", array_ptr[1]);
return 0;
}
4. What will be the output of the following program:
#include
int main ()
{
int foo = 1;
int bar = 2;
int * foo_ptr;
foo_ptr = & foo;
printf ("foo = %d ", foo);
*foo_ptr = 99;
printf ("foo = %d ", foo);
printf ("bar = %d ", bar);
foo_ptr = & bar;
printf ("foo = %d ", foo);
printf ("bar = %d ", bar);
printf ("* foo_ptr = %d ", *foo_ptr);
return 0;
}
5. Write the output of the following program. Assume that all necessary header files are included. Also the following function descriptions are given for your convenience:
islower() checks if character is lowercase letter
toupper() converts lowercase letter to uppercase
void Encrypt(char T[])
{
for (int i = 0; T[i] != '\0'; i += 2)
if (T[i] == 'A' || T[i] == 'E')
T[i] = '#';
else if (islower(T[i]))
T[i] = toupper(T[i]);
else
T[i] = '@';
}
int main()
{
char text[]="SaVE EArtH";
Encrypt(text);
cout << text << endl;
return 0;
}
6. Write the output of the following program if the input is This is a C programming class
#include
using namespace std;
int main( )
{
char str[80];
cout << "Enter a string: ";
cin.getline(str,80);
int words = 0;
for(int i = 0; str[i] != '\0'; i++)
{
if (str[i] == ' ')
{
words++;
}
}
cout << words+1 << endl;
return 0;
}
7. State true or false
strcmp("the", "them") is greater than 0.
strcpy (a,b) copies a to b, where a and b are two strings.
strlen(Im fine) is 8.
8.
struct Point
{
int x, y;
};
struct Line
{
Point a, b;
};
Line image[10];
State True/False for the above declarations
image is a struct
b) image[6] is an array
c) image[6].a is a struct
d) image[6].a.x is a struct
9. Print the y coordinate of the a point on the 6th line for the example in problem 8.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
