Consider the following program : #include<stdio.h> main( ) { int i, inp; float x, term=1, sum=0; scanf(“%d %f ”, & inp, &x); for(i=1; i<=inp; i++) { term = term * x/i; sum = sum + term ; } printf(“Result = %f\n”, sum); } The program computes the sum of which of the following series ?
\(x + x^{2}/2! + x^{3}/3! + x^{4}/4! + \ldots\)
The variable term starts at 1 and is multiplied by \(x/i\) in each iteration, so after iteration i it equals \(x^{i}/i!\).
i = 1: term \(= 1 \times x/1 = x\), sum \(= x\)
i = 2: term \(= x \times x/2 = x^{2}/2!\), sum \(= x + x^{2}/2!\)
i = 3: term \(= x^{2}/2! \times x/3 = x^{3}/3!\), and the pattern continues.
Check: the initial 1 is never added to sum (sum starts at 0), and the denominators are factorials, not plain integers.
Hence, \(x + x^{2}/2! + x^{3}/3! + x^{4}/4! + \ldots\).
What will be the output of the following ‘C’ code ?
main ( )
{ int x = 128;
printf (“\n%d”, 1 + x ++);
}
Code blocks allow many algorithms to be implemented with the following parameters :
Match the following with respect to the jump statements :
| List - I | List - II |
| a. return | i. The conditional test and increment portions |
| b. goto | ii. A value associated with it |
| c. break | iii. Requires a label for operation |
| d. continue | iv. An exit from only the innermost loop |
The control string in C++ consists of three important classifications of characters
Match the following with respect to I/O classes in object oriented programming :
| List - I | List - II |
| a. fopen() | i. returns end of file |
| b. fclose() | ii. return for any problem report |
| c. ferror() | iii. returns 0 |
| d. feof() | iv. returns a file pointer |
Which of the following is the correct value returned to the operating system upon the successful completion of a program ?
Given that \(x=7.5\), j = -1.0, n = 1.0, m = 2.0
the value of --x+j==x>n>=m is :
Which of the following is false regarding the evaluation of computer programming languages ?
Match the LIST-I with LIST-II
| LIST-I (FUNCTIONS) | LIST-II (Uses of functions) |
|---|---|
| A. fseek () | I. Gives the current position in the file |
| B. ftell() | II. Sets the position to the beginning of the file |
| C. feof () | III. Sets the position to a desired point in the file |
| D. rewind() | IV. Used to test for an end of file condition. |
Choose the correct answer from the options given below:
Consider following conditional statements if (m == 20 – 10 || n > 10). The order of execution of the following operations is
A. ==
B. –
C. ||
D. >
Choose the correct answer from the options given below:
Consider the following C program:
#include <stdio.h>
int g(int n) {
return (n+10);
}
int f(int n) {
return g(n*2);
}
int main() {
int sum, n;
sum=0;
for (n=1; n<3; n++)
sum + = g(f(n));
printf ("%d", sum);
return 0;
}
The output of the given C program is ____________ (Answer in integer)