0
460views
UNIVERSITY INSTITUTE OF ENGINEERING & TECHNOLOGY Theory Examination summer 2021 (B.Tech. Computer engineering) Subject: Fundamentals of Computer Programming.

Question 1: Attempt any four parts. [4×3.5=14]

  • a) Explain characteristic of an algorithm.

    b) Explain Application software.

    c) Define Digital computer.

    d) What is Linker?

    e) Define identifier.

Question 2: Attempt all parts. [2×7=14]

  • a) Explain the String handling function in detail.

    b) What is Pointer? Explain its advantages and disadvantages of it.

Question 3: Attempt all parts. [2×7=14]

  • a) Explain the math function in detail.

    b) Whata is function? Write a C program to calculthe ate factorial of a given number.

Question 4: Attempt all parts. [2×7=14]

  • a) Determine the hierarchy of operations and evaluate the following expression: on = inkact/2+3/2act+2+tig;

    ( ink = 4, act = 1, tig = 3.2, assume on to be an int)

    b) What are the differences betwtheen malloc () and calloc () function?

Question 5: Attempt all parts. [2×7=14]

  • a) What is purpose and use of Structure in C.

    b) What are the differences between while and do while loop?

Question 6: Attempt all parts. [2×7=14]

  • a) Explain passing arguments by value with suitable example.

    b) Explain the followings- (1) C Preprocessor (2) Macros

Question 7: Attempt all parts. [2×7=14]

  • a) Convert following number into:

    • (1) (10101.0101)2=(....)10

      (2) (93)10= (....)8

    b) Write a C program to find 37 is prime number or not.

1 Answer
0
2views

Full paper solution:


Question 1:


a) Explain characteristic of an algorithm.

An algorithm is a well defined produce that allows a computer to solve a problem.

Characteristics of an algorithm are:

(i) unambiguous:

Algorithm should be clear and unambiguous. Each of its step should be clear.

(ii) input:

An algorithm should have 0 or more well-defined inputs.

(iii) Outputs:

AN algorithm should have 1 or more well-defined outputs and should match the desired output.

(iv) Independent:

An algorithm should have step-by-step directions. Which should be independent of any programming code.


b) Explain Application software.

Application software:

  • Application software products are designed to satisfy a particular need of a particular environment.

    All software applications prepared in the computer lab can come under the category of application software.

    Application software may consists of a single program, such as microsoft's notepad for writing and editing a simple text.

    It may also consist of a collection of programs, often called a software package, which work together to accomplish a task, such as a spreadsheet package.

    So basically, it is a program or group of programs designed for end-users.


c) Define Digital computer.

  • A digital computer is a programmable machine. Which reads the binary instructions and process the data which are presented in binary form.

    Digital computers use the binary number system, which has two digits 0 and 1.

    A digital computer may be represented as:

    enter image description here


d) What is Linker?

  • Linker is a program that tacks one or more objects generated by a compiler and combines them into a single executable program.

    Linker also link a particular module into system library. It tacks object modules from assembler as input and form an executable files as output for leader.

    The linker links the object files to the library functions and the program becomes a ".exe file".

    Linker performs the process of linking. It is also called link editors.


Question 2:


a) Explain the String handling function in detail.

I) C string length: Strleh() function:

The strleh() function returns the length of the given string. It does not count null characters.

II) C string concatenation: Strcat() function:

THe Strcat (First- string, string- second) function concatenates two results and result is returned to first- string.

III) C copy string: Strcpy () Function:

The strcpy (destination, source) function copies the source string in the destination.

Iv) C compare string: strcmp () function:

The strcmp ( first_string, Second_string) function compares two string and return 0 if both strings are equal.

V) C stinrg uppercase: strupr () function:

The strupr (string) function returns string characters in uppercase.

VI) C string lowercase: strlwr () function:

The strlwr (string) function returns string characters in lowercase.

VII) C reverse string: strev () function:

The strev() function returns reverse of the given string.

VII) C string: strstr () function:

The strstr (string 1, string 2) returns a pointer to the first occurrence of string 2 in string 1.


b) What is Pointer? Explain its advantages and disadvantages of it.

Pointer:

  • A pointer is a variable that stores the address of another variable. Unlike other variable that holds values of a certain type. Pointer holds the address of a variable.

Advantages of pointers are:

i) Pointers provide direct access to the memory.

ii) Pointers provide a way to return more than one value to the functions.

iii) Pointers provides an alternate way to access array elements.

iv) Pointers reduces the storage space and complexity of the program.

v) Pointer reduces the execution time of the program.

Disadvantages of pointer are:

i) Pointers are slower than normal variables.

ii) Uninitialized pointe r ight cause segmentation fault.

iii) Dynamically allocated blacks needs to be freed explicity. Otherwise, it would lead to memory task.

iv) If pointers are updated with incorrect values, it might lead to memory corruotion.

v) Basically, pointer bugs are difficult to handle. So , use pointer effectively and correctly.

By using * oprator we can access the values of a variable through a pointer.


Question 3:


a) Explain the math function in detail.

i) Double ceil (double x):

The c library function double ceil ( double x) returns the smallest integer value greater than or equal to x.

ii) Double Floor (double x):

The c library function double floor (double x) returns the largest integer value less than or equal to x.

iii) Double log (double x):

The c library function double log (double x) returns the natural logarithm of x.

iv) Double fabs (double x):

The c library function double fabs(double x) returns the absolute value of x.

v) double log10 (double x):

The c library function double log10 (double x) returns the common logarithm (base 10 logarithm) of x.

vi) Double sqrt (double x):

The c library function double sqrt (double x) returns the square root of x.

vii) Double pow( double x, double y):

The c library function double pow (double x, double y) returns x raised to the power of y.

viii) Double .exp (double x):

The c library function double exp (double x) returns the value of e raised to the x the power.


b) What is function? Write a C program to calculate ate factorial of a given number.

Function:

  • A function is defined to be a self-contained program which is written for the purpose of accomplishing some task.

    It is a reusable block of code that makes a program easier to understand, test and can be easily modified without changing the calling program.

    Example:

enter image description here


Question 4:


a) Determine the hierarchy of operations and evaluate the following expression: on = inkact/2+3/2act+2+tig;

 on = ink * act/2 + 3/2 * act + 2 + tig;
  • (int=4, act=1, tig=3.2)

    so, the expression will be:

    on = 4 * 1/2 + 3/2 * 1 + 2 + 3.2

    = 4/2 + 3/2 * 1 + 2 + 3.2 (Operation : *)

    = 2 + 3/2 * 1 + 2 + 3.2 (Operation: /)

    = 2 + 1 * 1 + 2 + 3.2 (Operation: /)

    = 2 + 1 + 2 + 3.2 (Operation: *)

    = 5 + 3.2 (Operation: +)

    =8 (Operation: +)

    Therefore, the expression's answer will be,

    on = 8


b) What are the differences between malloc () and calloc () function?

Malloc () calloc ()
The name malloc stand for memory allocation. The name calloc stand for contiguous allocation.
It is used to dynamically allocate a single large block of memory with the specified size. It is used to dynamically allocate the specified number blacks off memory of the specified type.
Syntax: ptr=(data_type*) malloc (byte-size); Syntax: ptr = (float*) calloc(n, element-size)
malloc () taks one argument that is number of bytes Calloc() takes two arguments those are: number of blocks and size of each block.
It retunr a pointer to n bytes of uninitialized storage It returns a pointer to enough free space for an array of n objects of the specified size.
malloc () is faster than calloc() calloc () tacks little longer than malloc (), because of extra - step of initializing the allocated memory by 0.
Example: ptr = (int ) malloc(100sizeof(int)); Example: ptr = (float*) calloc(25.sizeof(float));
This statmet allocates 400 bytes of memory and ptr holds the address of first byte in the allocated memory. This statments allocates coniguous space in memory for 25 elements each with size of float.


Question :


a) What is purpose and use of Structure in C.

i) Struchure is a user-defined data type in C language will allows us to combine data of different types together.

ii) Structure helps to construct a complex data type which is more meaningful.

iii) It is similar to an array, but an array holds data of similar type only wich structure can hold data of any type.

iv) Ech element of a structure is called a member. It can store various information.

v) The struct keyword is used to define the structures in C language.

User of structures in C:

i) C strutures can be used to store huge data.

ii) C structures can be used to send data to the printer.

iii) This structures can interact with keybourd and mouse to store the data.

iv) C structure can be used to check computerr's memory size etc.

v) User a special data structure to store the collection of different data types.

vi) Structures can be used to clean output screen contents.


b) What are the differences between while and do while loop?

While loop Do-while loop
In this, the given condition is evaluated first and then loop body In this, the given loop body is executed first and then after the given condition is checked.
It is an entry- controlled loop It is an exit-controlled loop
The loop body would be executed, only if the given condition is true. The loop body be executed at least once, even if the given condition is false
It allows intialisation of counter variable before entering loop body. It allows intialisation of counter variable before and after entering loop body.
It is used Which condition evaluation is required to be evaluated first, before executing loop body. Do- while is used when one-needs to enter into the loop body before evaluating condition.
Syntax: While (condition) { //loop body } Syntax: do { // loop body } while (condtion);
Please log in to add an answer.