0% found this document useful (0 votes)
24 views5 pages

Bachelor of Computer Science & Engineering First Year, First Semester Examination

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)
24 views5 pages

Bachelor of Computer Science & Engineering First Year, First Semester Examination

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/ 5

Jadavpur University

Ex/ES/CM/T104A/2022

Bachelor of Computer Science & Engineering


First Year, First Semester Examination
Computer Programming and Numerical Methods
Session: 2021-22

Time: 3 Hours Full Marks: 100

Answer All Questions

1. Answer Any Two. 2 × 5 = 10


A. Draw a flowchart to find the sum of the following series: S = x − x3 + x5 − x7 . . . xn , where x and n are
provided as input.
B. Harshad (or Niven ) numbers are those numbers which are divisible by their sum of the digits. For
example 1729 ( 19 × 91 ) is divisible by 1+7+2+9 =19, so 1729 is a Harshad number. Develop an
algorithm to find out whether a given number is a Harshad number.
C. Develop an algorithm to accept as input an integer number of seconds, and to print the equivalent time
in hours, minutes and seconds. Example: if the input is 7322 seconds, the output should be “2 hours 2
minutes 2 seconds”.
D. Draw a flowchart to check whether the reverse of a 3-digit integer (given as input by the user) is the
integer itself.
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] 10 × 2 = 20

A
1
B
2 int f(int *a, int n){
1 void f(int *p, int *q){
3 if(n<=0) return 0;
2 p=q;
4 else if(*a%2 == 0)
3 *p=2;
5 return (*a+f(a+1, n-1));
4 }
6 else
5
7 return (*a-f(a+1, n-1));
6 int main(){
8 }
7 int i=0, j=1;
9
8 f(&i, &j);
10 int main(){
9 printf("%d %d\n", i, j);
11 int a[]={1,2,7};
10 return 0;
12 printf("%d", f(a,3));
11 }
13 return 0;
14 }

Page 1 of 5
Jadavpur University

D
1 int f(int j){
C 2 static int i=50;
3 int k;
1 int main(){
4
2 char inChar=’A’;
5 if(i==j){
3 switch(inChar){
6 printf("something");
4 case ’A’: printf("Choice A\n");
7 k=f(i);
5 case ’B’:
8 return 0;
6 case ’C’: printf("Choice C\n");
9 }
7 case ’D’:
10 else
8 case ’E’:
11 return 0;
9 default: printf("No Choice\n");
12 }
10 }
13
11 }
14 int main(){
15 f(50);
16 }

F
E 1 int f1(void);
2 int f2(void);
1 int func(int num){
3 int f3(void);
2 int count=0;
4 int x=2;
3 while(num){
5
4 count++;
6 int main(){
5 num>>=1;
7 int x=1;
6 }
8 x+=f1()+f2()+f3()+f2();
7 return(count);
9 printf("%d", x);
8 }
10 return 0;
9
11 }
10 int main(){
12
11 printf("%d\n", func(18));
13 int f1(){ int x=5; x++; return x; }
12 }
14 int f2() { static int x=5; x++; return x; }
15 int f3() { x*=10; return x; }

H
G
1 void f(int *p, int m){
1 void get(int n){
2 m=m+5;
2 if(n<1) return;
3 *p=*p+m;
3 get(n-1);
4 return;
4 get(n-3);
5 }
5 printf("%d", n);
6 int main(){
6 }
7 int i=5, j=10;
7 int main(){
8 f(&i, j);
8 get(3);
9 printf("%d", i+j);
9 }
10 }

Page 2 of 5
Jadavpur University

J
I
1 int f(int i){
1 #include <stdio.h>
2 return (i*i + 3) % 10;
2
3 }
3 void count(int n){
4 int main(){
4 static int d=1;
5 int i, j, A[10];
5 printf("%d ", n);
6 A[0] = i = 0;
6 printf("%d ", d);
7 while(1){
7 d++;
8 j = f(i);
8 if(n>1) count(n-1);
9 A[j] = A[i] + j;
9 printf("%d ", d);
10 if (A[j] > 20)
10 }
11 break;
11
12 i = j;
12 int main(){
13 }
13 count(2);
14 printf("%d,%d", A[i], A[j]);
14 }
15 }

L
K
1 int main(){
1 int main(){
2 char A[10] = "14FB61R23";
2 int x = 0;
3 int i, sum = 0;
3 if(x = 0)
4 for(i=0; A[i]; ++i){
4 printf("Case (a): %d", x);
5 if (A[i] < ’0’) continue;
5 else if (x -= 7)
6 if (A[i] > ’9’) continue;
6 printf("Case (b): %d", x);
7 sum += A[i] - ’0’;
7 else
8 }
8 printf("Case (c): %d", x);
9 printf("sum = %d", sum);
9 }
10 }

M N
1 int main(){ 1 #define SQR(x) (x*x)
2 int i, j, A[10][20], (*p)[20]; 2 #define CUBE(x) ((x)*(x)*(x))
3 for (i=0; i<10; ++i) 3 int main(){
4 for (j=0; j<20; ++j) 4 int a, b=2, c;
5 A[i][j] = 3*i - 2*j; 5 a=SQR(b+2);
6 p = A; 6 c=CUBE(b+3);
7 printf("%d,%d,%d", (**p)+5, **(p+5), 7 printf("%d\n", a);
8 *(*p+5)); 8 printf("%d\n", c);
9 } 9 }

P
O 1 int main()
1 int r(void){ 2 {
2 static int num=7; 3 int i,j,x=0;
3 return num--; 4 for(i=0;i<5;++i)
4 } 5 for(j=0;j<i;++j){
5 int main(){ 6 x+=(i+j-1);
6 for(r(); r(); r()) 7 break;
7 printf("%d",r()); 8 }
8 return 0; 9 printf("%d",x);
9 } 10 return 0;
11 }

Page 3 of 5
Jadavpur University

3. Answer Any Four. 4 × 5 = 20


A. Write a C program to display and find the sum of the series 1 + 11 + 111 + . . . upto n. For example if
n = 4, the series is : 1 + 11 + 111 + 1111. Take the value of n as input from the user.
B. Write a C program, that reads a value of n from user. It then dynamically allocates memory for n
integers, reads n integer values from the user and prints sum of product of consecutive numbers.
For example, if n = 7 and numbers are 4,5,2,5,6,4,7 then output is 4*5+5*2+2*5+5*6+6*4+4*7 = 122.
C. Write a C program which accepts value n from the user and prints the following pattern (when n = 5)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

D. Write a non-recursive function that will take a character string as a parameter and will return its length.
Also write a recursive function to do the same job.
E. Write a C program that take 2 integer sets A[] and B[] as input and prints results of the set operation
A union B. Use arrays to represent sets.
F. Write a C program that reads in a C source program file and determines whether all the parenthesis are
balanced.
4. Answer Any Two. 2 × 7 = 14
A. Solve the following system of linear equations using Gauss Jordon method

8x − y + z = 18
x + y − 3z = −6
2x + 5y − 2z = 3

B. Determine the real root of the equation f (x) = −0.5x2 + 2.5x + 4.5 using three iterations of the Bisection
method. Employ initial guess of xl = 5 and xu = 10. Compute the relative error after each iteration.
C. Determine the distance travelled for the following data. Here, t represent time and v(t) represent
velocity at time t.

t 1 2 3.25 4.5 6 7 8 9 9.5 10


v(t) 5 6 5.5 7 8.5 8 6 7 7 5

Use (a) Trapizoidal Rule (b) Simpson’s 1/3 rd Rule.


D. The following data were collected for the distance travelled (y) versus time (t) for a rocket:

t(in sec) 0 25 50 75 100 125


y(in Km) 0 32 58 78 92 100

Use numerical differentiation to estimate the rocket’s velocity and acceleration at each time.
5. Answer Any Two. 2 × 8 = 16
A. The following table gives premium payable at the ages in years completed. Use Lagrange’s formula to
find the premium payable at the age of 50 years.

Age Completed in Years 25 30 40 60 70


Premium in Rs. 50 55 70 95 120

Page 4 of 5
Jadavpur University

B. Find the best straight line fitting the following data:

x 3.4 4.3 5.4 6.7 8.7 10.6


y 4.5 5.6 6.8 8.1 10.5 12.7

C. The voltage V across a capacitor at time t seconds is given by the following table. Use the principle of
least squares to fit a curve of the form v = aekt to the data.

t 0 2 4 6 8
V 150 63 28 12 5.6

dy
D. Given dx = x2 + y, y(0) = 1 determine y(0.02), y(0.04) and y(0.06) using Euler’s modified method.
6. Answer Any Two. 2 × 10 = 20

A. Write a C function for implementing the Bisection Method to return the root of a nonlinear equation
f(x)=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 f(x)
is already defined whose prototype is
double f(double x);
B. 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.
C. Write a C function for implementing the Jacobi method for determining the solution of a set of lin-
ear equations. The function should have four parameters: n - number of unknowns, a[n][n+1] - the
augmented matrix, e – allowed relative error, m – maximum number of iterations. The function should
return the solution vector.
D. Write a C function which evaluates integral of the function f (x) = x3 +3x+1 using Simpson’s 1/3rd rule.
The function should accept three parameters a, b, h, where a and b are the two end-points, between
which the integral has to be evaluated and h is the step size.

Page 5 of 5

You might also like