NPTEL Problem Solving Through Programming In C Week 8 Assignment Answers
Q1. A function prototype is used for
a. Declaring the function logic
b. Calling the function from the main body
c. Telling the compiler, the kind of arguments used in the function
d. Telling the user for proper use of syntax while calling the function
Answer: c. Telling the compiler, the kind of arguments used in the function
For Answers Updates Follow Us on Telegram
Q2. What is the output of the following C program?
#include<stdio.h>
void foo(),f();
int main()
{
f();
}
void foo()
{
printf("2");
}
void f()
{
printf("1");
foo();
}
a. Compiler error as foo() is not declared in main
b. 1 2
c. 2 1
d. Compile-time error due to declaration of functions inside main
Answer: b. 1 2
Q3. What is the error in the following program
#include<stdio.h>
int f(int a)
{
a>20? return(10): return(20);
}
int main()
{
int b;
b=f(20);
printf("%d\n",b);
}
a. Error: Return statement cannot be used with conditional operators
b. Error: Prototype declaration
c. Error: Two return statements cannot be used in any function
d. No error
Answer: a. Error: Return statement cannot be used with conditional operators
Q4. 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("Result is=%0.2f", result);
}
float func(float age[])
{
int i;
float result, sum=0.0;
for(i=0;i<6;++i) {
sum+=age[i];
}
result=(sum/6);
return result;
}
a. Result is=27.08
b. Result is=27.083334
c. Compiler error as result is declared twice
d. Error: Invalid prototype declaration
Answer: a. Result is=27.08
Q5. How many times the function get() will be invoked if get(6) is called from the main function.
void get(int n)
{
if(n<1) return;
get(n-1);
get(n-3);
}
a. 6 times
b. 25 times
c. 12 times
d. Infinite times
Answer: b. 25 times
Q6. What is the output of the following C program?
#include<stdio.h>
int fun(int n)
{
int i,j, sum=0;
for(i=1;i<=n;i++) for(j=i;j<=i;j++)
sum=sum+j;
return(sum);
}
int main()
{
printf("%d",fun(5)); return 0;
}
a. 25
b. 5
c. 15
d. 10
Answer: c. 15
Q7. What will be the output?
#include<stdio.h>
int main()
{
{
int a=70;
}
{
printf("%d",a);
} return 0;}
a. 70
b. Garbage value
c. Compilation error
d. None
Answer: c. Compilation error
Q8. What will be the output?
#include<stdio.h>
int f(int n,int k)
{
if (n==0)
return 0;
else if(n%2)
return f(n/2,2*k)+k;
else return f(n/2,2*k) -k;
}
int main()
{
printf("%d",f(20,1));
return 0;
}
a. 5
b. 8
c. 9
d. 20
Answer: c. 9
Q9. Consider the function
int fun(x: integer)
{
If x>100 then fun=x-10;
else
fun=fun(fun(x+11));
}
For the input x=95, the function will return
a. 89
b. 90
c. 91
d. 92
Answer: c. 91
Q10. Consider the function
int func(int num)
{
int count=0;
while(num)
{
count++;
num>>=1;
}
return(count);
}
a. 9
b. 8
c. 0
d. 10
Answer: a. 9
Disclaimer: These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.
Also Available:
Joy of Computing Using Python NPTEL Assignment Answers Week 8