Bachelor of Engineering First Year, First Semester Examination, 2023
Bachelor of Engineering First Year, First Semester Examination, 2023
Ex/ES/CM/T104A/2023
Bachelor of Engineering
First Year, First Semester Examination, 2023
Computer Programming and Numerical Methods
Time: 3 Hours Full Marks: 100
A
B
1 int main(){
1 int func(int num){
2 int i=1, j=1;
2 int count=0;
3 for( ; ; ){
3 while(num){
4 if(i>5)
4 count++;
5 break;
5 num>>=1;
6 else
6 }
7 j+=i;
7 return(count);
8 printf("%d\n", j);
8 }
9 i+=j;
9 int main(){
10 }
10 printf("%d\n", func(435));
11 return 0;
11 }
12 }
C D
1 void f(int *p, int *q){ 1 int main(){
2 p=q; 2 int i,j,x=0;
3 *p=2; 3 for(i=0;i<5;++i)
4 } 4 for(j=0;j<i;++j){
5 int i=0, j=1; 5 x+=(i+j-1);
6 int main(){ 6 break;
7 f(&i, &j); 7 }
8 printf("%d %d\n", i, j); 8 printf("%d",x);
9 return 0; 9 return 0;
10 } 10 }
Page 1 of 4
Jadavpur University
E F
1 int jumble(int x, int y){ 1 int func(int num){
2 x=2*x+y; 2 int count=0;
3 return x; 3 while(num){
4 } 4 count++;
5 int main(){ 5 num=num>>1;
6 int x=2, y=5; 6 }
7 y=jumble(y,x); 7 return(count);
8 x=jumble(y,x); 8 }
9 printf("%d\n", x); 9 int main(){
10 return 0; 10 printf("%d\n", func(20));
11 } 11 }
G
1 int main(){ H
2 int i, j, count; 1 int main(){
3 count=0; 2 int a[]={10,15,-1,56,67,5,4};
4 i=0; 3 int *p,*q;
5 for(j=-3;j<=3; j++){ 4 p=a;
6 if((j>=0)&&(i++)) 5 q=&a[0]+3;
7 count=count+j; 6 printf("%d\n",(*p)++);
8 } 7 printf("%d\n", *(++p));
9 count=count+i; 8 printf("%d\n",*(--q));
10 printf("%d\n", count); 9 return 0;
11 return 0; 10 }
12 }
J
I 1 int Func(int x, int y){
1 void fun1(char *s1, char *s2){ 2 if((x==1)||(y==1))
2 char *tmp; 3 return 1;
3 tmp = s1; 4 if(x==y)
4 s1 = s2; 5 return x;
5 s2 = tmp; 6 if(x>y)
6 } 7 return Func(x-y, y);
7 int main(){ 8 if(y>x)
8 char *str1 = "Hi", *str2 = "Bye"; 9 return Func(x, y-x);
9 fun1(str1, str2); 10 }
10 printf("%s %s\n", str1, str2); 11 int main(){
11 } 12 printf("%d\n", Func(25, 10));
13 }
K L
1 #define SQR(x) (x*x) 1 int main(){
2 #define SQR2(x) ((x)*(x)) 2 int i=0;
3 int main(){ 3 while(i<=2){
4 int a, b=2; 4 int i = 1;
5 a=SQR(b+2); 5 i++;
6 printf("%d\n", a); 6 printf("%d\n", i);
7 printf("%d\n", SQR2(a+b)); 7 }
8 } 8 }
Page 2 of 4
Jadavpur University
Write a C program to accept name, roll and marks in three subjects for 10 students and store it in an
array of struct student. Your program should print the name and roll number of the student who has
obtained the highest aggregate marks.
D. A text file stores an integer value in each line. Write a C program that reads that text file and prints
maximum and minimum value stored in it.
E. Write a C function which accepts two strings A and B: char *f(char *A, char *B). The function
dynamically allocates memory to hold a third string obtained by concatenating string B after string A.
The function should return the third string. Call the function from main(). Do not use any string library
function.
F. Write a C program to read elements in a n × n matrix and check whether the matrix is upper triangular
matrix or not. The program should take n as input and allocate memory for the matrix dynamically.
4. Answer Any Two. 2 × 9 = 18
A. Use Gauss-Jordon or Jacobi method method to solve the following system of linear equations:
20x + y − 2z = 18
3x + 20y − z = 41
2x − 3y + 20z = 36
B. Determine the real root of the equation f (x) = x3 + 2x2 + 3x + 2 using three iterations of the Bisection
or False Position method. Employ initial guess of xl = −5 and xu = 5. Compute the relative error after
each iteration.
C. Compute the values of Z 1
dx
0 1 + x2
1 rd
using the Trapizoidal rule and Simpson’s 3 rule with h = 0.25. Compare your result with the true
values.
dy
D. Solve, using (a) Euler’s method and (b) Modified Euler’s method, the equation dx = x + y, y(0) = 0.
Choose h = 0.2 and compute y(0.4) and y(0.6).
Page 3 of 4
Jadavpur University
B. Use linear regression method to fit a straight line to the following data.
x 0 2 4 6 9 11 12 15
f(x) 5 6 7 6 9 8 7 10
C. Given the following data, estimate the value of f (22) and f (42) using Newton’s forward difference and
backward difference formulae respectively.
x 20 25 30 35 40 45
f(x) 354 332 291 260 231 204
D. An investigator has reported the data tabulated below. It is known that such data can be modeled by
y−b
the equation x = e a , where a and b are parameters. Use a transformation to linearize this equation
and then employ linear regression to determine a and b.
x 1 2 3 4 5
f(x) 0.5 2 2.9 3.5 4
A. Write a C function for implementing the Gauss-Jordon method for determining the solution of a set of
linear equations. The function should have two parameters: n - number of unknowns, a[n][n+1] - the
augmented matrix. The function should return the solution vector. Call the function from main().
B. Write a C function for implementing the Newton-Raphson method to return the root of a nonlinear
equation f (x) = 0. The function should accept one parameter as the initial guess of the root. Assume,
the function f (x) and its derivative f ′ (x) are already defined whose prototypes are:
double f(double x);
double fd(double x);
Call the function from main().
C. 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 f(x) is already defined
whose prototype is
double f(double x);
Call the function from main().
Page 4 of 4