Question 1
#include<stdio.h>
int main()
{
printf(\"%c\\n\", ~(\'C\' * -1));
return 0;
}
Question 2
The function f is defined as follows:
int f (int n) {
if (n <= 1) return 1;
else if (n % 2 == 0) return f(n/2);
else return f(3n - 1);
}
Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
1. The function f terminates for finitely many different values of n ≥ 1.
ii. The function f terminates for infinitely many different values of n ≥ 1.
iii. The function f does not terminate for finitely many different values of n ≥ 1.
iv. The function f does not terminate for infinitely many different values of n ≥ 1.
Which one of the following options is true of the above?
Question 3
int i ;
program main ()
{
int j = 60;
i = 50;
call f (i, j);
print i, j;
}
procedure f (x, y)
{
i = 100;
x = 10;
y = y + i ;
}
Question 4
# include <stdio.h>
int main ()
{
char a [6] = \"world\";
int i, j;
for (i = 0, j = 5; i < j; a [i++] = a [j--]);
printf (\"%s\\n\", a);
}
/* Add code here. Remove these lines if not writing code */
Question 5
# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
int tmp;
tmp = a; a = b; b = tmp;
}
void swap3 (int*a, int*b)
{
int tmp;
tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
int num1 = 5, num2 = 4, tmp;
if (num1 < num2) {swap1 (num1, num2);}
if (num1 < num2) {swap2 (num1 + 1, num2);}
if (num1 >= num2) {swap3 (&num1, &num2);}
printf (\"%d, %d\", num1, num2);
}
/* Add code here. Remove these lines if not writing code */
Question 6
#include <stdio.h>
int main ()
{
int i, j;
int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
for(i = 0; i < 3; i++) {
a[i] = a[i] + 1;
i++;
}
i--;
for (j = 7; j > 4; j--) {
int i = j/2;
a[i] = a[i] - 1;
}
printf (\"%d, %d\", i, a[i]);
}
/* Add code here. Remove these lines if not writing code */
Question 7
int A[100][100]; int main() { for(int i=1; i < 100 ; i++) for(int j=1; j < 100;j++) A[i][j] = (i/j)*(j/i); return 0; }What will be the sum of the all the elements of double dimensional array A after implementing the above function ?
Question 8
#include <stdio.h>
int counter = 0;
int calc(int a, int b) {
int c;
counter++;
if (b == 3)
return (a * a * a);
else {
c = calc(a, b / 3);
return (c * c * c);
}
}
int main() {
calc(4, 81);
printf(\"%d\", counter);
}
Question 9
#include
#define EOF -1
void push (int); /* push the argument on the stack */
int pop (void); /* pop the top of the stack */
void flagError ();
int main ()
{ int c, m, n, r;
while ((c = getchar ()) != EOF)
{ if (isdigit (c) )
push (c);
else if ((c == \'+\') || (c == \'*\'))
{ m = pop ();
n = pop ();
r = (c == \'+\') ? n + m : n*m;
push (r);
}
else if (c != \' \')
flagError ();
}
printf(\"% c\", pop ());
}
Question 10
#include <stdio.h>
struct Ournode {
char x, y, z;
};
int main() {
struct Ournode p = {\'1\', \'0\', \'a\' + 2};
struct Ournode *q = &p;
printf(\"%c, %c\", *((char *)q + 1), *((char *)q + 2));
return 0;
}
There are 10 questions to complete.