WBUT Question Papers EE Introduction To Computing B Tech 2nd Sem 2006

WBUT Question Papers EE

Introduction To Computing B Tech 2nd Sem 2006

 

Time : 3 Hours

Full Marks: 70

Group-A

(Multiple Choice Questions)  ‘

  1. 1.   Choose the correct alternative in each of the following :

10×1 = 10

(a)    The function ftell ( )

(i) reads a character from a file, (ii) reads an integer from a file, (iii) gives the current position in a file, (iv) none of these.

(b)    Members of a union use—(i) different storage locations (i) same storage locations (iii) no storage locations (iv) none of these.

(c)    main ( )

{ . • ‘ ‘ int x = 7, y = 5 ; ,

. x = y++ + x++ ,         ‘                    .

y -++y -H-+x ;         .•

printf (“%d%d”, x, y) ;

■’ } – ‘

Output:’                        .

(i) 12 14 (ii) 12 20 (iii) 9 7 (iv) 12 19.

(d)    main ( )

{ / – ■ ’ . ; int sum, i;

for (i = 0 ; i < = 10 ; 1++)

. { . if (i%2) continue ;     .

sum = sum + i ;

printf (“%d”, sum);

} 1 Output:

(i) 55 (ii) 30 (iii) 23 (iv) 42                   ‘  *

(e)    # define SQR(A) A*A            . main ( )

 

int x = 5 ;

int y ;                  ,

y = 4*SQR (x – 3);         . .

printf (“%d”, y);

Output:

(i) 8 (ii) 64 (iii) 16 (iv)- 52

(f)     ALU is a part of a

. (i) memory (ii) CPU (iii) output device (iv) input device.

(g)    ASCII value of‘A’is                  •

. (i) 97 (ii) 65 (iii) 48 (iv) 67 ,

(h)    main ( )

{ ” . int i = 2 ; switch (i)

{

case 1 : printf (“One”) ;          .      .

case 2 : printf (“Two”) ;

case 3 : printf (“Three”) ;    ’

default : printf (“Error”) ;

} ‘

} . • . . Output :

(i) One Two Three Error (ii) Two (iii) Two Three Error (iv) Two Three

(i)      main ( )

■ < . ‘ int i, j ; ,

for (i — 0 J = 5 ; i < j ; i++, j++) ; ’ printf (“%d%d”, i, j);

} /

Output:

(i) 3 2 (ii) 0 5 1 4 2 3 (iii) Error (iv) Infinite loop.    t

(j) A 32-bit microprocessor has the word length equal to

(i)  2 bytes (ii) 1 byte (iii) 4-bytes (iv) 8 bytes.

 

. Ans. 1. (a)(iii) ; (b)(ii) ; (c) None (output: 1 4 2 1) ; (d) None (sum is not initialised); (e) None (output 2) ; (f)(ii) ; (g)(ii) ; (h)(iii) ; (i)(iv); 0)0*0

Group-B

Note : (i) Each answer should not exceed 50 words.

(ii)  Answer any three questions.

  1. 2.                                                                                                                                                                                                                                                           Answer any five of the following questions in brief :                 3×5

(a)     Write a complete C program to generate a Fibonacci series.

(b)    Write a C program to find the sum of 2 matrices.

(c)     Write a C program to convert Centigrade to Fahrenheit and vice versa.

(d)   Using ternary (conditional) operator, write a ‘C’ program to find the largest of three numbers.                  ,   .

(e)     Differentiate between Do-while and While statements with suitable examples.

(f)      Differentiate between Break and Continue statements with examples.

(g)     What is dynamic memory allocation? Write about malloc and calloc functions.

Ans. (a)

#  include <stdio.h>

#  include < conio.h>

Void main ( )

{ – . . ‘ int n, x = 1, y = 1, z, i ; clrscr ( ) ;

Printf (“\n Enter the no. Of terms you want to display in Fibonacci series \n”) ;

Scanf (“%d”, & n);

Printf (“\n The fiboracci series is\n”) ;

Printf (“%d%d”, x, y); // First two terms ‘

‘ for (i = 0 ; i < n — 2 ; i ++)      ,

{ ‘ ‘

.     z = x + y;    • .         / ” .      ’

x = z ;           •           • ■

Printf (“\t% d”, z),;

} . • . getch ();               •

or,

 

Void main ( )

. – int n, x= 1, y = 1, z ; clrscr ( );

Printf (“\n Enter the value upto which you want to print \n”) Scaaf (“%d”, & n) ;

Printf (“\n The fiboracci series is \n”);  ‘

Printf (“%d%d”, x, y) ; while (x<=n)  .

f , , .. ‘

\ z = x + y :                .

y = x ;                1

x = z ;

Printf (“%d”, z) ;

} getch; ( ) ;

}

Ans. (b)

#   include < stdio.h>

#  include <conio.h>

#  define ROW 5 // Row dimension equal to 5

#  define COL 5 it Column dimension equal to 5 void main ( )

{ • ‘ int a [ROW] [COL], b [ROW] [COL],

C[ ROW] [COL], i,j ;clrscr(); –   .

Printf (“\n Enter the matrix a ….\n”) ; for (i = 0 ; i'< ROW ; i++) // input to matrix a {

for (j ? 0 ; j < COL ; j++)

{ ; \ ‘

Print (“\n Enter the element a [%d] [%d] = ”)

Scanf(“%d”, & a[i] [j]);

} . .

{ – Printf (“\n Enter the matrix b … \n”);

For (i = 0 ; i < ROW ; j++) // input to matrix b

 

{ ‘ ■ for .(j = 0 ; j < COL ; j++)

{ – . ‘ ‘ . . • ‘ Printf (*\n Enter the element b [%d] [%d]”);

Scanf (“%d”, & b[i] [j]) ; }}

Printf (“\n The a matrix is \n”) ;    t,

for (i = 0 ; i < ROW ; j++) // output to matrix a

{ ’ . for (j = 0 ; j < COL ; j++)

{ : : • ” Printf (“\t % d”, a[i] [j]) ;

} , ■ ■ Printf (“\n”);

} • . .

Printf (“\n The b matrix is \n”) ;

For (i = 0 ; i < ROW ; i++)

{ …

For (j = 0 ; j < COL ; j++)

{ ‘ • ‘

Printf (“\t % d”, b[i] [j]) ;    .

} • ‘ Printf (“\n”) ; ‘

} . ‘ ‘ For (i = d ; i < ROW ; i++) // for sum of two matrix Cy = a^ + by { .

} }

C [i] U1 = a {i] [j] + b[i] [j]

} . ‘ . Printf (“\n The output matrix c is \n”) ;  ”

For (i = 0 ; i < ROW ; i++) .

{ . .

For (j = 0 ; j < cOL ; j++)

{ ‘

. ‘Printf (“\n % d”, c [i] [j]) ;

        _

Printf (“\n”);

getch ( ); }                                                                          •

Ans. (c) Refer to the answer Question No. 2(c) of year 2005. • ‘    .

Ans. (d) To know about ternary operator See the answer Question No. ‘6(c) of year 2002.

#  include. < stdio.h > .

#   include < conio.h >                             • void main ( )

< ” ■ • int a, b, c, large_num ; clrscr ( ) ; .

Printf (“\n enter the number a \n”) ;               ‘

Scanf (“%d”, 8a) ;                 .

Printf (“\n enter the number b\n”) ;

Scanf (“%d”, &‘ c) ;

large_num = (a > b) ? ((a > c)? a : c) : ((b > c)? b : c) •

Printf (“\n The largest number is % d”, large_num) ;

geten ( )                                                                                                                    ^                ‘

} – ■ • Ans. (e) Refer to the answer Question No. 4(c) of year 2002.

Ans. (f) Refer to the answer Question No. 10(iii) of year 2004.

Ans. (g) Refer to-the answer Question No. 9(e) of year 2005.

  1. 3.    (a) With a suitable block diagram, briefly explain the major components and their

functions of any conventional computer.

(b) State the basic features of any structured programming language.  .

Ans.(a). Refer to the answer Question No. 3(a) of year 2002.

Ans. (b) Refer to the answer Question No. 3(c) of year 2002.

  1. 4.            (a).  What is the type casting? What is the automatic type conversion?

(b)  Explain unary operation with example.

(c)  Write a C programe to check whether a given number is prime number or not. Ans. (a)                               .

Void main ( )

{ – -■ ‘ / ■ ‘ ‘

int x = 5, y = 2 , z; .                 .

float z; . .

Clrscr ( ) ;                        ,

z = x/y;    – .            .

Printf (“% f\z) ;                             ”

getch ( );}                                    .                           ■

The above c-program will give the output i.e., z = 2.000000. Because c compiler does not know that integer integer division can produce float. So, we have to type cast. Type costing, is a process by which we can force fully cast the data type to the variable. According to above program we can type cast x as follows.

void main ( )                             .

{ ‘ ‘ int x = 5, y = z ; float z

1                           f

z = (float) x/y ; 1    type casting

Printf (“%■f’,z) ;

} ‘ .

In type casting there is a need to store a value of one type into a variable of another

type. In such situations, we must cost the value to be stored by proceeding it with the type name in parentheses. The syntax is :   .

type variable 1 = (type) variable 2 ;

type casting       ‘           ,

It is possible to asign a value of one type to a variable of a different type without a cast. This is know as automatic type conversion.

In semantic analysis phase of compiler the automatic type conversion is done. Generally lower byte variable is converted to upper byte variable. In above program after type casting the x variable, y variable automatically converted from mt to float. After that float, float division will produce float. Automatic type conversion also called implicit type conversion.

Ans. (b) Unary operator takes one operand to operate. For example ++ (increment) and -­(decrement) operator.

++ and — both are unary operators and are used in the following form :

++ m or m ++ (m is single operand) ;

postincrement         .

-preincrement ++ m or m++ is equivalent to

m = m + 1 ;                                     •

—     m or m — (m is single operand)

Predecrement post decrement – – m or m — is equivalent to m = m – 1 ; other unary operators are !, – (unary, minus)

+ (unary plus), ~ etc.

Ans. (c)                      –

#   include < stdio.h >             .                  ..

#   include < conio.h > , void main ( )

{ • int n , i, flag = 0 ;

Printf (“\n enter the number \n”)

Scanf (“% d”, & n) ;

for (i = 2 ; i < = n – 1 ; i++)

{ • ‘

If (n % i = = 0)                         .       •

{

flag = 1 ;                            ^

. break ;

} ’ } ■

If (flag = = 0)

Printf (“\n The given number is prime \n”) ; else

Printf (“\n The given number is not prime \n”) ;

getch.(.);}                                         ,

S.  What is recursion? Write a recursive C function to find the factorial of a positive integer that is received as argument to the function.                                                                                    5

–                                                                                                                                                                                                                                                   Ans. Refer to the answer Question No. 4(b) of year 2003.                  ‘

. # include < stdio.h >

#  include < conio.h >

unsignd int factorial (int); // function protyping Void main ( )

■ ; ■ . , ;

Unsigned int n ; fact;

Printf (“\n enter the positive number \n”) ;

Scanj (“% u”, & n) ;

fact = factorial (n); ■•

Printf (“\n The factorial of % n is % u\n”, n, fact) ; geten ( );                     ’

} . . • • ■ ■ : ‘ unsigned int factorial (unsigned int P)

If (p = = 0)                             – ■ ‘

return (1); .

hr-; fekse                                                                                                      ■

return (n * factorial (n – 1)) ; }    ■   1

  1. 6.    Explain “Call by by value” and “call by referecae”. mechanism for passing arguments into a function call in general. Develop a function in C that will swap (exchanged) the value of two integer variables passed as arguments. Also write the main program.   5

Ans. Refer to the Answer Question No. 8.(a) of year 2003.

Group-C             ,

. Note : Answer any three of the following questions. 3*15= 45

  1. (a) What is a file ? Write the Instructions in C for creating a file.                2+4

(b) Write a complete C program* to copy file fi.dat assuming fi.dat is available in your current working directort.                                                                                                       9

Ans. (a) File is a collection of records. In other point of view file is a logical storage unit

by which it gives an abstraction to user about die physical storage device. For example

x.dat, x.doc, x.txt etc.

. File name extension

#  include < stdio.h >

#  include < conio.h >

Void main ( )

{ ‘

FILE * fpr;

, fpr = fopen (“File name”, “mode”) ; .

// mode may be

r/w/a/r+/w+/a+/rb/wb

etc (read/write/oppend etc)

II     input to file/working to file     ■

f close (fptr);}        .        ‘

fopen ( ) function open a file of specified file name according to mode (read/write/apper n etc). After working on file close the file by felose ( ) function.

WBUT (2nd Sem)—35                                      –

 

Ans. (b) Refer to the answer Question No. 9 (a) of year 2003 and Question No. ll(ii) of year 2004.

  1. 8.  (a) What is structure in C? How Is it declared?

(b)   Declare a structure temple having members of appropriate type branch            .           /

name                     .                 –

roll No

marks in 8 subjects.

Write a C program to create an array of 30 structure variables and read ail the members of each variable.                                                                                                             9

Ans. (a) Refer to the answer Question No. 10(ii) of year 2004 and Question No. 4(a) of

year 2005.  .

Ans. (b)                                                                                   t

#  include < stdio.h>

#  include < conio.h >

struct student                       .

r int rollno;

char name [ 20 ]; chor branch { 20 ] ; float marks [8] ;

} s [30] ; //array of 30 structure variables.

Void main ( )

{ • * ‘ ‘ int i ;                    .

for (i — 0 ; i < 30 ; i ++)           –                    .

Printf (“\n enter the roll no of student \n”)

Scanf(“%d”,&s [i], rollno); ’     ;

Printf (“\n enter the name of student \n”)              .

Scanf (“%S , s[ij . name) ; //gets (s[i].naitte) ;

Printf (“\n enter the branch of student \n”) ;

Scanf (‘As”, s[i].branch ; // gets (s[i].branch)

Printf (“\n enter the marks of-1st subject \n”) ;

Scanf (“%f’, & s[i].marks[o]) ;

Printf (“\n enter the marks of 2ndsubject An”) ;   ..

Scanf (“%d” , +s[i]. marks [i]);

Printf (“\n Enter the marks of 3rd Subject \n”);

Scanf (“% f”, & s[i].marks [2]) ; .

Printf (‘An enter the marks of 4th subject”) ;

Scanf (“% f ”, & s[i],marks [3]) ; ‘  . ”       ’

 

Printf (“\n enter the marks of 5th subject”);

Scanf (“%f”, & s[i],marks [4]);

Printf (“\n enter the marks of 6th subject \n”); .

Scanf r%f”, & s[i].marks [5]);

Printf (“\n enter the marks of 7th subject \n”);

Scanf (“% f”, & s[i].marks [6]);

Printf (“\n enter the marks of 8th subject \n”);

Scanf (“% f\ & s[i],marks [7]);

  • getch ();

} •

link float ( ) *lt is special function fral till help to link the float data type. Generally turbo compiler requires this function to take the input of float type. Otherwise problem may create for taking float type input oo.

< •

float a = 0, * ptr ;

Ptr = oo a ;

*  Ptr = a ;

} –

  1. 9.                                                                                                                                                                                                                                                                        (a) Distinguish between recursion and iteration.                                                                                                        5

(b)     Write a reccursive program to compute factional of a number read from key­board.         10

Ans. (a)

Recursion

Interation
1 When a function called by itself then it is called recursion.

  1. Recursion requires base value condition to terminate.
  2. Generally two type of recursion—(i) Direct (ii) Indirect.
  3. Recursion requires stack, it increase time and space complexcity of program.
  4. Example.

X( ){

If (condition) —> Base value condition

x ( );

}

  1. The process of repeatedly executing a block of statements is known as iteration or loop.
  2. Interation or loop requires terminating condition to terminate.
  3. Generally two type of loop or iteration—(i) Entry central (while ) (ii) exit control (do- while).
  4. Generally iteration requires less space and complencity w.r.t. recusion.
  5. Example,

for (initialization ;

termmating condition ; increa…/decrenat) executable statement ;

}

 

Aiu.(b). Refer to the Answer Question No. 5 of the year 2006.

Note : one mistake in problems, factional will factorial.

  1. 10.    (a) Write short notes on the following :

(a) Pointers in C (b) Bitwise operators (c) Operating system. Ans.(a) Pointer is a variable who holds the address of an another variable. For example

int *ptr ; *ptr is a pointer variable holding the oddres of an integer variable

int x = 5, y ;

r

ptr = 4x ; // pointer intializatism y = *ptr ; ptr is holding the address of x

2000

Pointer can be incremented or decremented Refer to the answer 10(i) of year 2004.

Ans. (b) Refer to the Answer 12(ii) of year 2003. Ans. (c) Refer to the Answer 2(a) of year 2002.

Leave a Comment