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

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Page 1 of 4

Ex/ES/CM/T104A/2019

Bachelor of Engineering First Year First Semester Examination, 2019


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 the reverse of a positive integer read as input.
B. Draw a flow chart for finding out whether a given positive integer is prime or not.
C. Draw a flow chart for finding the product of individual digits of a positive integer
read as input.
D. Draw a flow chart for finding the distance between two points given as input.

2. Determine the output of the following program snippets. Include brief justifications.
[Answer any ten]
10x2=20

A main(){ B main(){
int i=5, j=2; int a, b=10;
float a, b=2, c; a=(b>5)?b++:b--;
a=i/j; printf("%d %d\n", a, b);
c=i/b; }
printf("%f %f\n", a, c);
}
C main(){ D main(){
int i; int a=2, b=3, c=1;
int j=0;
printf("%d\n", a<<1+b);
for(i=0; i<50;i++){ printf("%d\n", a+b>>c>2);
if(i%7==0) }
j++;
}
printf("%d\n", j);
}
E main(){ F main(){
int i, j, k=1; int i, n;
char *x = "India";
for(i=1;i<=3;i++){
for(j=1;j<=i;k += i,j++) n=strlen(x);
printf("%d ", k); *x = x[n];
printf("\n"); for(i=0; i‹n; i++){
} printf("%s\n",x);
} x++;
}
}
G main(){ H void test(void){
unsigned char i = 127; static int j;
char j=i+1; j++;
printf("%d\n", j);
printf("%d\n", j); }
} main(){
test();
test();
}

I main(){ J main(){
int i=5; int i=5; j=2;
printf("%d %d", i>>1); printf("%d %d %d", i|j, i&j, i^j);
printf("%d %d", i<<2); }
}

Moderated by Signature of Paper-Setter in full


Page 2 of 4

K main(){ L #define square(x) x*x


int a[10]; main(){
printf("%d",*a+1-*a+3); int i;
} i = 64/square(2+2);
printf("%d\n", i);
}
M main(){ N #define CUBE(x) ((x)*(x)*(x))
int i=5; main(){
printf("%d", ++i); int a, b=2;
printf("%d", i++); a=CUBE(b+3);
} printf("%d", a);
}
O void main(){ P main(){
int i=0; int i;
while(i<=2){ int count = 5;
int i = 1; int sum = 0;
i++; for(i=10; i>count; i--){
printf("Hello\n"); sum += i;
} }
} printf("sum is %d\n", sum);
}

3. Answer any four.


5x4=20

A. Write a C function f(Col, a[][Col], i, j, b) which accepts five arguments


(all integers) and updates the ith row of the matrix a as 𝑅𝑖 = 𝑅𝑖 + 𝑏 × 𝑅𝑗 . Col is the
column size.
B. Write a C program which prints first hundred prime numbers.
C. Write a C program which determines whether a given string is palindrome or not. Do
not use any string library function.
D. Write a C program which accepts names, rolls and marks of 10 students in 6 subjects
and stores it in an array of structures. The program should print roll, name, and the
total of 6 subjects for all the students.
E. Write a C program that accepts a date as a string in “dd/mm/yyyy” format from the
user, and prints the date in “month-date-year” format after checking validity
(check only the number of days in a month without considering leap years) of the
date entered. Example: If the input date is “16/04/2012”, the program should print
April-16-2012.
F. Write a C program which dynamically allocates memory for two matrices (of the
same order). The program reads the order and the elements of the matrices from the
user. The program creates a third matrix which is obtained by adding the two input
matrices.

4. Answer any two


7x2=14

A. Find the second (at the end of 2 iterations) iterative value of the root of 𝑥 3 − 3𝑥 2 +
5 = 0 in the domain of 𝑥 ∈ [1, 5] using Bisection OR False-Position method.

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


method.
20𝑥 + 𝑦 − 2𝑧 = 17
3𝑥 + 20𝑦 − 𝑧 = −18
2𝑥 − 3𝑦 + 20𝑧 = 25

C. A jet fighter’s position on an aircraft carrier’s runway was timed during landing.

𝑡 (sec) 1.0 1.1 1.2 1.3 1.4 1.5 1.6


𝑦 (meter) 7.989 8.403 8.781 9.129 9.451 9.750 10.031

Moderated by Signature of Paper-Setter in full


Page 3 of 4

where, 𝑦 is the distance of the jet fighter from the end of the runway. Estimate the
𝑑𝑦
velocity at (i) 𝑡 = 1.1, (ii) 𝑡 = 1.6 using Newton’s Forward Difference formula.
𝑑𝑡

D. A ball at 1200K is allowed to cool down in air. Assuming heat is lost only due to
radiation, the differential equation for the temperature of the ball (𝜃 in K) is given by
𝑑𝜃
= −2.2067 × 10−12 (𝜃 4 − 81 × 108 )
𝑑𝑡
Find the temperature of the ball at 𝑡 = 480 second using Euler’s method. Assume,
𝜃(0) = 1200𝐾 and a step size of ℎ = 240 seconds.

E. The velocity of a body is given by

𝑣(𝑡) = 2𝑡, 1 ≤ 𝑡 ≤ 5
𝑣(𝑡) = 5𝑡 2 + 3, 5 < 𝑡 ≤ 14

where, 𝑡 is given in seconds, and 𝑣 is given in m/s. Using 2-segment Simpson’s 1/3rd
Rule OR Trapezoidal Method, find the distance covered by the body from 2 to 9
seconds.

5. Answer any two.


8+8=16

A. Use the method of least squares to fit a quadratic curve through the following data:

𝑥 0 5 10 15 20
𝑓(𝑥) 7 11 16 20 26

Estimate the value of 𝑓(25)

B. Consider the following data from the steam table

Temperature in °C 140 150 160 170 180


Absolute Pressure in bar 3.685 4.854 6.302 8.076 10.225

Find the pressure at temperature 152 °C using Newton's Forward Difference method.

C. Find the values of 𝑎, 𝑏 and 𝑐 so that 𝑌 = 𝑎 + 𝑏𝑥 + 𝑐𝑥 2 is the best fit to the data.

𝑥 0 1 2 3 4
𝑦 1 0 3 10 21

D. An experiment on the life of a cutting tool at different cutting speeds gave the
following values:

Speed 𝑣 in 𝑓𝑡/𝑚𝑖𝑛 350 400 500 600


Life 𝑇 in 𝑚𝑖𝑛 61 26 7 2.6

It is known that 𝑣 and 𝑇 satisfy the relationship 𝑣 = 𝑎𝑇 𝑏 . Using the method of least
squares find the best values of 𝑎 and 𝑏.

Moderated by Signature of Paper-Setter in full


Page 4 of 4

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 OR Jacobi's method for


solving a system of linear equations.
B. Write a C program for implementing Lagrange’s polynomial interpolation. Inputs to
the program are 𝑛, arrays 𝑋 and 𝑌 which contain 𝑛 + 1 numbers of 𝑥 and 𝑓(𝑥)
values respectively, 𝑥𝑖 is the point where the value of the function 𝑓 has to be
interpolated. Output of the program is 𝑓(𝑥𝑖 ). [Use dynamic memory allocation for 𝑋
and 𝑌]
C. Write a C program for implementing the Newton-Raphson Method to return the root
of a nonlinear equation 𝑓(𝑥) = 0. Consider the initial estimate of the root (𝑥0 ) as
user input. Assume the functions 𝑓(𝑥)and 𝑓 ′ (𝑥) are already defined which take a
double as parameter and return a double.
D. Write a C function to populate the augmented matrix for solving a set of equations to
fit an 𝑛𝑡ℎ order polynomial curve (by using Least-Square Method) through 𝑚 number
of data points. The augmented matrix, 𝑛, 𝑚 and the data points are to be passed as
parameters.

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

Moderated by Signature of Paper-Setter in full

You might also like