Bachelor of Engineering First Year First Semester Examination, 2021 Computer Programming & Numerical Methods
Bachelor of Engineering First Year First Semester Examination, 2021 Computer Programming & Numerical Methods
Ex/ES/CM/T104A/2020
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);
}
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();
}
1
1 2
1 2 3
1 2 3 4
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
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);
--------|--------