Programming in C and Data Structures - Dec 2014

1 (a) What is pscudocode? Explain with an example.

Answer: A pseudocode is an algorithm expressed in a natural language rather than a programming language. It provides programmers a detailed template for the next step of writing instructions in a specific programming language. Writing a pseudocode is a part of the design phase in software...

1 (b) Explain the structure of C program with an example.

Answer: A C program consists basically of: Preprocessor Directives Function(s) Variable declarations Executable statement Comments Example: #include <stdio.hint main() { intnum = 29; /* This line will print Computer Engineering as outpu...

1 (c) Explain any five operators used in C language.

Answer: Operator is a symbol that represents a particular operation to be performed on some data. The data is called as operand and hence operator operates on an operand. Operators are classified as unary, binary and ternary depending on the number of operands. Based on the operation per...

10 (a) What are primitive and non primitivedatatypes? Explain.

Answer: Data Type Adata typeis a classification of data, which can store a specific type of information. Data types are primarily used in computer programming, in which variables are created to store data. Each variable is assigned a data type that determines what type of data t...

10 (b) Define queue. Explain it along with its application.

Answer: Queue Queue is also an abstract data type or a linear data structure, in which the first element is inserted from one end calledREAR(also called tail), and the deletion of exisiting element takes place from the other end called asFRONT(also called head). This makes queue...

10 (c) Explain: i) Abstract data type ii) Stack iii) Linked list.

Answer: Abstract datatype: Data type can be considered abstract when it is defined in terms of operations on it, and its implementation is hidden. Linked list : Linked list is a set of elements, usually structures, where each element contains a pointer or index to the "nex...

2 (b) Write a program in C to find the area and perimeter of a rectangle.

Answer: #include<stdio.hintmain() { int a, b, area, perimeter; printf("enter length and breadth of rectangle"); scanf("%d%d",&a,&b); area=a*b; perimeter=2*(a+b)...

2 (c) Define: i) Variable ii) Constant iii) Associativity iv) Precedence.

Answer: 1. Variable C variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable.The value of the C variable may get change in the program.C variable might be belonging to any of the data type like int, ...

3 (a) What is two way selection statement? Explain if, if-else, nested if-else casaded if-else with...

Answer: Twoway selection statement The basic decision statement in the computer is the two-way selection. The decision isdescribed to the computer as a conditional statement that can be answered either true or false.If the answer is true, one or more action statements are execu...

3 (b) Write a program that takes three coefficients (a, b and c) of a quadratic equation: (ax2+bx+c)1 as...

Answer: #include <stdio.hintmain(void) { int a, b, c, d; scanf("%d%d%d", &a, &b, &c); printf("%dx^2 + %dx + %d = 0", a, b, c); //prints the equation d = b*b-4*a*c; //discrimin...

4 (a) Explain switch statement with an example.

Answer: Switch Statement: "switch" is conditional or selection statement that will be normally used to select one set of statements from 2 or more alternative sets of statements .Such a selection can be done using if else statement also but if there are more than 2 sets of s...

4 (b) What is a loop? Explain the different loops in C language.

Answer: There are 3 types of loops in C .They are as follows : for loop , do while , while loop. FOR LOOP: This loop is used when we know the no.of iterations to be done so we should implement this loop oly when the number of times the loop should be repeated is ...

4 (c) Show how break and continue statements are used in a C program, with example.

Answer: The break and continue statement are the jumping statement. The break statement We often have come across situations where we want to jump out of a loop instantly, without waiting to get back to the conditional test. The keyword break allows us to do this. When break is encount...

5 (a) What is an array? How is a single dimension array is declared and initialized?

Answer: Array is a collection of items of same data types that will be referred as single name .C langauage supports one dimensional and multi dimensionalarray.We now that a variable can hold one value at a time so if we want to store many elements at a time in memory we have to use as variab...

5 (b) Write a C program to evaluate the polynomial

f(x)−a4x4+a3x3+a2x2+a1x+a0,

for...

Answer: #include <stdio.h> #define N 4 //4-degree polynomial int main(){ int x, a, ans; scanf("%d", &x); for(inti = 0; i < N+1; i++){ //there will be 5 coefficients for a 4-degree polynomial nbs...

5 (c) Explain string manipulation functions, with examples.

Answer: There are numerous functions defined in"string.h"header file.some string handling functions are discussed below: Function Work of Function strlen() Calculates the length of string str...

6 (a) What is a functions? Write a function to find the sum of two numbers.

Answer: A C program consists of one or more functions with one main() function. Functions are blocks of programs that perform some specific and well-defined task. It breaks large complicated computing tasks into smaller and simpler ones. It helps in maintainence and enhancement of progr...

6 (b) Explain the two categories of argument passing techniques., with examples.

Answer: Passing Argument to Function In C Programming we have different ways of parameter passing schemes such as Call by Value and Call by Reference. Functionis good programming style in which we can write reusable code that can be called whenever require. Whenever we call a func...

6 (c) Write a C function isprime(num) that acepts an integer argument and return 1 if the argument is a...

Answer: #include <stdio.hintisPrime(n){ if(n==1) return 0; for (inti = 2; i <= (int)sqrt(n); i++) if(n%i==0) return 0; return 1; } int main(void) { int low, high;...

7 (b) Show how a structure variable is passed as a parameter to a function, with an example.

Answer: Passing Argument to Function In C Programming we have different ways of parameter passing schemes such as Call by Value and Call by Reference. Functionis good programming style in which we can write reusable code that can be called whenever require. Whenever we call a func...

7 (c) Explain the concept of array of structures with a suitable C program.

Answer: A Structure is a collection of same or different datatypes that are collectively representing a entity as student ,an employee, a rectangle,a complex number etc. In C structure is one of the derived data types using which one can create a user defined data type . ...

8 (a) What is a file? Explain fopen(), fclose() functions.

Answer: A file, is a self contained piece of information available to theoperating systemand any number of individual programs.Information inside the file could consist of essentially anything but whatever the file contains is likely related some how.nb...

8 (c) Give two text documentary files "Ramayana" and "Mahabharatha-in". Write a C program to create a new...

Answer: #include <stdio.h> #include <conio.h> #include <stdlib.hintmain() { FILE *fs1, *fs2, *ft; FILE *p,*q;char dh,ph; nb...

9 (a) What is a pointer? Write a program in C to find the sum and mean of all elements in an array. Use...

Answer: Definition: A variable that stores a address of another variable is known as pointer variable or we can say a variable that can point to another variable is called as a pointer variable. Memory addess of the variable is actually a unsigned integer. If a is the integer then &...

9 (c) Explain: i) Dynamic memory allocation ii) Malloc function

Answer: (i) Dynamic Memory Allocation The process of allocating memory at runtime is known asdynamic memory allocation. Library routines known as "memory management functions" are used for allocating and freeing memory during execution of a program. These functions are defin...