Week 8 July 2023
Week 8 July 2023
Week 8 July 2023
a) 70
b) Garbage value
c) Compilation error
d) None
a) Infinite times
b) 32767
c) 65535
d) Till stack overflows
5. How many times ‘Hi’ will be printed in the program given below
#include<stdio.h>
int i;
int fun();
int main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}
a) Only once
b) Zero times
c) Infinite times
d) Compilation error
Solution: (b) The default value of i is ‘0’. Thus, the while loop will never be executed and the
control will not come into the function. Thus, ‘Hi’ will never be printed.
Assignment 8 Solution
As n =5, so the function factorial() calls itself 5 times. In addition, factorial() function is
called once from the main(). So, total 6 times the function factorial() will be executed.
int main ()
{
int a = 2048, sum = 0;
func (a, sum);
printf ("%d ", sum);
}
a) 8 ,4, 0, 2, 14
b) 8, 4, 0, 2, 0
c) 2, 0, 4, 8, 14
d) 2, 0, 4, 8, 0
Assignment 8 Solution
Solution: (d) 2, 0, 4, 8, 0
sum has no use in func(), it is there just to confuse. Function func() just prints all digits of a
number. In main, there is one more printf statement after func(), so one more 0 is printed after
all digits of n.
a) 55
b) 45
c) 66
d) 10
Solution: (a) The program finds the sum of the integer numbers till 10. Thus the output is
55.
a) Maximum of a, b
b) Positive difference between a and b
c) Sum of a and b
d) Minimum of a and b
0 if x<y
x-y if x>y
Assume in the first case a>b so find(a,b) will return (a-b). So find(a,find(a,b)) will be
find(a,a-b) which will return (a-(a-b))= b which is the minimum number.
Now if a<b then find(a,b)=0 so find(a,find(a,b))=find(a,0) which will return (a-0)=a
which is the minimum number. So, the code actually returns a minimum of two numbers.
10. What is the output of the C code given below
#include <stdio.h>
float func(float age[ ]);
int main()
{
float result, age[] = { 23.4, 55, 22.6, 3, 40.5, 18 };
result = func(age);
printf("%0.2f", result);
return 0;
}
Ans: 27.08