Question
sum(n)
{
if ( n < 1 ) return n;
else return (n + sum(n–1));
}
main()
{
printf(“%d”, sum(5));
}
a.
10
b.
16
c.
15
d.
14
Posted under UGC NET computer science question paper Programming in C
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the output of the following program segment? sum(n) { if ( n < 1 ) return n; else return (n + sum(n–1)); } main() { printf(“%d”, sum(5)); }
Similar Questions
Discover Related MCQs
Q. Assume that x and y are non-zero positive integers. What does the following program segment perform?
while (x!=0)
{
if (x>y)
x = x-y
else
y=y-x;
printf(“%d”,x);
View solution
Q. Consider the following program segment:
d=0;
for(i=1; i<31, ++i)
for(j=1; j<31, ++j)
for(k=1; k<31, ++k)
if ((i+j+k)%3)= = 0);
d = d + 1;
printf(“%d”, d);
The output will be
View solution
Q. Consider the following two function declarations :
(i) int *f( )
(ii) int (*f)( )
Which of the following is true ?
View solution
Q. Assume that we have constructor function for both Base and Derived classes. Now consider the declaration :
main ( )
Base *p = new Derived;
In what sequence, the constructor will be executed ?
View solution
Q. A Program contains the following declarations and initial assignments:
int i = 8, j = 5;
double x = 0.005, y = –0.01;
char c=’c’, d=’d’;
Determine the value of the following expressions which involve the use of library functions:
abs(i-2*j) ; log(exp(x)) ; toupper(d)
View solution
Q. MPEG involves both spatial compression and temporal compression. The spatial compression is similar to JPEG and temporal compression removes .............. frames.
View solution
Q. The programming languages C and C++ are not strongly typed languages because :
View solution
Q. When the following code is executed what will be the value of x and y?
int x = 1, y=0;
y = x++;
View solution
Q. How many values can be held by an array A(-1,m;1 ,m) ?
View solution
Q. What is the result of the expression
(1&2)+(3/4) ?
View solution
Q. How many times the word 'print' shall be printed by the following program segment?
for(i=1, i≤2, i++)
for(j=1, j≤2, j++)
for(k=1, k≤2, k++)
printf("print/n")
View solution
Q. Arrays in C language can have ................. with reference to memory representation.
View solution
Q. Refer the points as listed below:
(a) What are the operator precedence rules ?
(b) What are the operator associativity rules ?
(c) What is the order of operand evaluation ?
(d) Are there restrictions on operand evaluation side effects ?
Which of the above must be considered as primary design issues for arithmetic expressions ?
View solution
Q. When an array is passed as a parameter to a function which of the following statements is correct?
View solution
Q. Trace the error:
void main( )
{
int *b, &a;
*b = 20
printf(“%d, %d”, a, *b)
}
View solution
Q. Match the following:
a. calloc( ) i. Frees previously allocated space
b. free( ) ii. Modifies previously allocated space
c. malloc( ) iii. Allocates space for array
d. realloc( ) iv. Allocates requested size of space
Codes:
a b c d
View solution
Q. printf(“%c”, 100);
View solution
Q. The ………….. memory allocation function modifies the previous allocated space.
View solution
Q. The goal of operator overloading is
View solution
Q. How many of the following declarations are correct?
int z = 7.0;
double void = 0.000;
short array [2] = {0, 1, 2};
char c = “\n”;
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Programming in C? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!