0% found this document useful (0 votes)
19 views4 pages

Bachelor of Engineering First Year First Semester Examination, 2021 Computer Programming & Numerical Methods

Uploaded by

Arijit Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Bachelor of Engineering First Year First Semester Examination, 2021 Computer Programming & Numerical Methods

Uploaded by

Arijit Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Page 1 of 4

Ex/ES/CM/T104A/2020

Bachelor of Engineering First Year First Semester Examination, 2021


Computer Programming & Numerical Methods

Time – 3 Hours Full Marks – 100

Answer All Questions

1. Answer any two


5x2=10

A. Draw a flow chart to print all the integers between 0 and 100 which are divisible by n,
where n is a positive integer read as input.
B. Draw a flow chart to print the sum of squares of individual digits of a positive integer
read as input.
C. Draw a flow chart to determine whether a string read as input is palindrome or not.
D. Draw a flow chart to print all Fibonacci numbers within n, where n is a positive integer
read as input.

2. Determine the output of the following program snippets. Include brief justifications.
Assume that all necessary libraries have been included and there is no syntax error.
[Answer any ten]
10x2=20

A main() { B main(){
int i, j, count = 0; int x=0;
for (i = 10; i >= 0; i--) { while(x<=2){
for (j= 10;j >= 0;j--) { int x = 0;
if ((i+j)%7 == 0) x++;
count++; printf("Hello\n");
} }
} }
printf("Count=%d\n", count);
}
C main(){ D main(){
char *s = "Hello, World"; int b=55;
printf("%c %c", *s+4, s[4]); for( ; b; b=b>>1)
} printf("%d\n", b);
}
E #define square(x) x*x F main(){
main(){ int a[5]={1, 5, 3, 4, 2};
int i; int *p, *q;
i = 64/square(2+2);
printf(“%d\n”, i); p=a;
} q=a+3;
printf("%d %d %d\n", *(a+1), *a+1, q-p);
}

G main(){ H main(){
int i=0; float x;
do{ x=4>5?3*6+7-2:3>2?5+4-3*2:64;
i++; printf("%f", x);
if(i%10) }
continue;
printf("%d\n", i);
}while(i<50);
}
I main(){ J main(){
int a[4]={5, 4, 3, 2}; int i=8; j=5;
int *p=&a[1]; printf(“%d %d %d”, i|j, i&j, i^j);
printf("%d\n", *p++); }
printf("%d\n", ++*p);
}

Moderated by Signature of Paper-Setter in full


Page 2 of 4

K main(){ L main(){
int var=10; int i;
char a[8]={0,1,2,3,4,5,6,7};
printf("%d", ++var==11); char *p=a;
} for(i=0;i<5;i++)
*(p+i) += 'a';
*(p+i) = '\0';
printf("%s\n", a);
}
M void test(void){ N main(void){
static int j; int i, y, z, count=0;
j++; for(i=1; i<3; i++){
printf(“%d\n”, j*j); y=count++;
} z=++count;
main(){ }
test(); printf("%d,%d",y,z);
test();
}

3. Answer any four.


5x4=20

A. Write a C function int ishappy(int n) which takes as argument an integer n and


returns 1 if n is a happy number and 0 otherwise. If you iterate the process of summing
the squares of the decimal digits of a number and if the process terminates in 1, then
the original number is called a Happy number. For example 7 is a happy number as 7
-> 49 -> 97 -> 130 -> 10 -> 1.
B. Write a C function f(int x) which accepts a positive integer as argument and returns
the difference between highest and lowest digit present in that integer argument. For
example f(1234) should return 3 and f(20980) should return 9.
C. Write a C function which takes as argument two strings str1 and str2. It creates a
third string str3 which is formed by taking alternate characters from each string and
returns it. Example: If the two string arguments are “abcd” and “efgh” the function
should return the string “aebfcgdh”.
D. Write a C program which accepts a multiword string (may be an empty string) and
prints the number of words in it. Assume that, there are no leading/trailing blanks
before/after the first/last word, but there may be multiple blanks between words.
[Example: If the input string is “Ram is a good boy”, your program should print
“No. of words = 4”]. Do not use any string library function.
E. Write a C program that reads a text file and prints the total number of alphabetic and
numeric characters in the file. Name of the text file is to be taken as input.
F. Write a C program that prints the following pattern for n lines, where the value of n is
taken as input. Example: when n is 4 the program should print the following:

1
1 2
1 2 3
1 2 3 4

4. Answer any two


7x2=14

A. Solve the system of linear equations using Gaussian-Elimination OR Gauss-Jordon


method.
5𝑥 + 𝑦 − 2𝑧 = 4
𝑥 + 2𝑦 − 5𝑧 = −2
2𝑥 − 3𝑦 + 2𝑧 = 1
5
B. Evaluate∫4 log 𝑥 𝑑𝑥 using Simpson’s 1/3rd formula and compare the result with the
exact value. Take step size=0.2.

Moderated by Signature of Paper-Setter in full


Page 3 of 4

C. Find a real root of the function 𝑓(𝑥) = 𝑥 3 − 2𝑥 2 + 𝑥 + 7 using Bisection method up


to 3 significant figures. Consider the initial bracket as [-5, 5].
𝑑𝑦
D. Using the following table, find at x=1.1
𝑑𝑥

x 1.0 1.1 1.2 1.3 1.4 1.5 1.6


y 7.989 8.403 8.781 9.129 9.451 9.750 10.031

5. Answer any two.


8+8=16

A. Construct the difference table from the following table and compute f (18) by
Newton’s backward formula.

x 0 5 10 15 20
f (x) 1.0 1.6 3.8 8.2 15.4

B. Find the interpolating polynomial which corresponds to the following data using
Lagrangian interpolation formula.

x -1 0 2 5
f (x) 9 5 3 15

C. Find the values of 𝑎0 and 𝑎1 so that 𝑌 = 𝑎0 + 𝑎1 𝑥 fits the data given in the following
table.

𝑥 0 1 2 3 4
𝑦 1.0 2.9 4.8 6.7 8.6
𝑥
D. Use the principle of least squares to fit a curve of the form 𝑦 = to the following
𝑎+𝑏𝑥
data.

𝑥 8 10 15 20 30 40
𝑦 13 14 15.4 16.3 17.2 17.8

6. Answer any two.


10+10=20

Note: (i) Two Real Numbers may be considered equal if their absolute difference is less than
10-6], (ii) Input/Output should be handled in main()

A. Write a C program for implementing the Gauss-Seidel method for solving a system of
linear equations.
B. Write a C function for implementing the False Position Method to return the root of a
nonlinear equation (𝑥)=0. The function should accept four parameters a, b, e, n: such
that a single real root lies in the range [a, b] with error tolerance e and maximum
number of iterations n. Assume, the function 𝑓(𝑥) is already defined whose prototype
is
double f(double x);

C. Write a C function for implementing the Lagrange’s method for polynomial


interpolation. The function should accept four parameters x, y, n, p: such that x and y
are two arrays of size n containing [x, y] values for n data points. The function
should return the interpolated value at x=p.

Moderated by Signature of Paper-Setter in full


Page 4 of 4

D. Write a C function integrate(a, b, h) that returns the integration of a given


function within limits a and b with a step size h using the Trapezoidal method.
Assume, the function 𝑓(𝑥) is already defined whose prototype is
double f(double x);

--------|--------

Moderated by Signature of Paper-Setter in full

You might also like