NITT Coding Que
NITT Coding Que
Semester Examination
Date: 18.03.2021 year/Semester : I/I
Max Marks: 30 Max Duration : 2Hr
Answer all the Questions
Note: You can assume that #include<stdio.h>, #include<conio.h>, and
#include<math.h> is included in the program.
1. Write the output of the following programs. You can assume that there is no
error in the program. Fifty percent marks for correct answer and 50 % marks for
justification.
(f)
int funcf (int x);
int funcg (int y);
main()
{
int x = 2, y = 5, count;
y += funcf(x) + funcg(x);
printf ("%d ", y);
}
funcf(int x)
{ int y;
y = funcg(x);
return (y);
}
funcg(int x)
{ static int y = 10;
y += 1;
return (y+x); (2)
}
(j) Suppose base address is 1000 (a=1000) for the following problems. Write the
output of the following programs.
int main () { int a[5][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8}};
printf("%d%d%d\n", (*(a+2))[1], *(a+2)+1, *a[1] + 1 );
return 0;
(2)
(k)
int main()
{
char s1[ ] = "beautiful big sky country",
s2[ ] = "how now brown cow";
strcpy(s1+8,s2+8);
printf("%s\n", s1);
return 0;
} (1)
(l)
struct {
int s[5];
union {
float y;
char z;
}u;
} t;
2(a). Following questions, if there is no error in the program then you have to write
objective of the program else you write the error in the program.
(i) void main() {
int a[]={6,7,8,9,10};
a = a + 4;
for (i =0, i<4, i++);
printf("%d",*(a-i);) } (1)
(ii) int main()
{ char *str[10], *t;
int i,j;
for(i=0;i<5;i++)
scanf("%s",str[i]);
for(i=0; i<5; i++)
for(j=i+1; j<5; j++)
if (strcmp(str[j-1], str[j]) > 0)
{
t=str[j];
str[j]=str[j-1];
str[j-1]=t;
}}}
printf("\n");
for(i=0;i<5;i++)
printf("%s\n",&str[i]); } (1.5)
(c) Consider the following recursive C function that takes two arguments
unsigned int foo(unsigned int n, unsigned int r) {
if (n > 0) return (n%r + foo (n/r, r ));
else return 0;
}
(i) What is the return value of the function foo when it is called as foo(513, 2)?
(ii) What is the return value of the function foo when it is called as foo(345, 10)?
(2.5)
3.(a) Kunwar sequence: sequence in which each number is the sum of the three
preceding numbers, starting from 0, 0 and 1.
Write the program in C which displays Kunwar sequence up to nth term where n is
entered by user. (2)
(b) Write the function Revstrhalf in c which takes string (with even length) and
returns the same string with first half is reversed and second half is same.
char* Revstrhalf (char*s)
For example: input: abcdxyzu
Output: dcbaxyzu (2.5)
… … … …
… … … … … (3)
(d) Write a C-program to calculate difference between two time period. For example
difference between 2:54:55 - 4:00:50 is 1:05:55 (h:m:s). While taking input from
user, you should not assume that first time period is greater than second or vice-
versa. You have to use structure and function (named difference to compute time
difference). Time difference should be printed in main function (Hint: call by
reference). (4)
end