Sie sind auf Seite 1von 37

SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

PREVIOUS YEAR’s AND MODEL PAPER


QUESTIONS AND REFERENCES

Previous Years: 2016, 2015, 2014 and 2013

Model Papers: MP-1, MP-2

1. Answers and References for ONLY 1st Module.

2. From Module 2 to 5 , questions with reference to the prescribed textbook and one
reference book.

3. Answers to all questions can be found in the supporting material given by the faculty.

4. Also you can find the answers for the questions in the handwritten notes given by me
which is posted in the xlearn portal and class notes.

TB1: Programming in C by Pradip Dey and Manas Gosh, Second Edition

RF1: Programming in C by Reema Thareja, First Edition

Material: Supporting Material posted in the xlearn.

Notes: hand written notes posted in the xlearn ad notes given in the class.

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

MODULE-I

PART-1A: INTRODUCTIO TO PROGRAMMING, ALGORITHMS & FLOWCHARTS


1. What is the difference between an algorithm and a flowchart? Explain with an example. (Nov,
15)

Answer:

1. From notes given in the class.

2. TB1: Pg 14-1.9.1-Definition, Pg 26-Definition, Pg 21-Q9, Pg 28-Q25.

3. Material: Pg 18-1.7, Pg23.

Algorithm:

Advantages:

Disadvantages:

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

Example:

Flowchart:

Advantages:

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

Disadvantages:

Example:

2. Write an algorithm and draw flowchart for finding the biggest among the given three numbers?
(Nov, 13)

Answer:

1. From notes given in the class.

2. TB1: Pg 21-Q9, Pg 28-Q25.

Algorithm:

Let the three numbers be represented by A, B and C.

1. START

2. PRINT “ ENTER THREE NUMBERS”

3. INPUT A, B, C

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

4. IF A>=B AND B>=C

THEN PRINT A

5. IF B>=C AND C>=A

THEN PRINT B

ELSE

PRINT C

6. STOP

Flowchart:

3. What is a top-down design? Discuss. (Nov, 13)

Answer:

1. From notes given in the class.

2. TB1: Pg 12-1.8.1.

3. Material: Pg 16-1.6.1

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

Top-down analysis breaks the whole problem into smaller logical tasks and defines the hierarchical
link between the tasks.

There are 4 steps:

i. Define the complete scope of the problem to define the basic requirement for its solution.

Input: What data is required to be processed by the program?

Process: What must be done with the input data?

Output: What information should the program produce?

ii. Divide the problem into two or more parts.

iii. Define the scope of each of these separate tasks and sub-divide them further if necessary into
two or more smaller tasks.

iv. Repeat step3 until the task becomes simple and cannot be broken further.

4. What are the steps to follow for solving problem by using a computer (Nov, 13)

Answer:

1. From notes given in the class.

2. TB1: Pg 13-1.8.4.

3. Material: Pg 17-1.6.4

To make the program operational, the programmer has to follow some logical and sequential job
steps:

1. Understand the problem to be solved

2. Think and design the solution logic

3. Write the program in the chosen programming language

4. Translate the program to machine code

5. Test the program with sample data

6. Put the program into operation.

5. Describe the two major categories of software with examples. (MP-1)

Answer:

1. from notes given in the class.

2. TB1: Pg 2-1.1.1 and 1.1.2.

3. Material: Pg 3-1.2

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

6. Define and differentiate between assembly and high-level languages. (MP-1)

Answer:

1. from notes given in the class.

2. TB1: Pg 4-Assembly language and Pg 5-1.2.4

3. Material: Pg 7- Assembly language and Pg 9-1.3.4

7. Explain the functionality of the following. (MP-2)(Nov,16)

i. Preprocessor

ii. Compiler

iii. Linker

iv. Loader

Also write down the differences between compiler and interpreter. (Nov, 15)

Answer:

1. from notes given in the class.

2. TB1: Compiler-Pg 6-1.3 and figure 1.7, Linker-Pg 7 1.3.2, loader- Pg 7-1.3.3

Differences- Pg6-Table 1.1

3. Material: Pg 10-1.4.1 and Pg 11-1.4.3 differences, Pg 11-1.4.4

i. Preprocessor:

The C preprocessor, often known as cpp, is a macro processor that is used automatically by
the C compiler to transform your program before compilation. It is called a macro processor because
it allows you to define macros, which are brief abbreviations for longer constructs.

It is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C
Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-
processing before the actual compilation.

All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character,
and for readability, a preprocessor directive should begin in the first column.

ii. Compiler:

It is a program which translates a high-level language program into a machine language


program. A compiler is more intelligent than an assembler. It checks all kinds of limits, ranges,
errors etc. But its program run time is more and occupies a larger part of the memory.

It has slow speed because a compiler goes through the entire program and then translates the
entire program into machine codes. If a compiler runs on a computer and produces the machine
codes for the same computer then it is known as a self-compiler or resident-compiler. On the

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

other hand, if a compiler runs on a computer and produces the machine codes for other
computer then it is known as a cross-compiler.

iii. Linker:

In high level languages, some built-in header files or libraries are stored. These libraries are
predefined and these contain basic functions which are essential for executing the programs. These
functions are linked to the libraries by a program called Linker. If linker does not find a library of a
function, then it informs to compiler and then compiler generates an error. The compiler
automatically invokes the linker as the last step in compiling a program.

Not only built-in libraries, it also links the user-defined functions to the user-defined libraries.
Usually a longer program is divided into smaller subprograms called modules and these modules
must be combined to execute the program. The process of combining the modules is done by the
linker.

8. What is a algorithm? Write a algorithm to find out whether a given number is a prime. (MP-2)

Answer:

1. from notes given in the class.

2. TB1: Pg 14-1.9.1, 1.9.3, Pg 24-Q16

3. Material: Pg 18-1.7.1, 1.7.3, differences

Definition:

An algorithm is an effective procedure for solving a problem in a finite number of steps. A well-
designed algorithm has termination and correctness properties.

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

Properties of an Algorithm:

Algorithm to find out whether a given number is a prime:

1. START

2. PRINT “ENTER THE NUMBER”

3. INPUT N

4. IF N=2 THEN

PRINT “CO-PRIME” GOTO STEP 12

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

5. D :=2

6. Q:=N/D (INTEGER DIVISION)

7. R:=N-Q*D

8. IF R=0 THEN GOTO STEP 11

9. D:=D+1

10. IF D<=N/2 THEN GOTO STEP 6

11. IF R=0 THE

PRINT “NOT PRIME”

ELSE

PRINT “PRIME”

12. STOP

8. Define programming. Discuss about different types of programming languages (Nov, 16)

Answer:

1. from notes given in the class.

2. TB1: Pg 1-1.1, 1.2

3. Material: Pg 4-1.3

9. How is memory reserved using a declaration statement? Explain in detail with eg’s (Nov, 16)

Answer:

Memory is reserved using data type in the variable declaration. A programming language
implementation has predefined sizes for its data types.

Example: int a; // a variable is created with size 4 bytes

char b; //variable b is created with size 1byte

PART-1B: BASICS OF C
1. Write short notes on basic data types that the C-language supports. (Nov, 15)

(OR)

2. How many types of variables are supported by C-language (Nov,16)

Answer:

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

1. from notes given in the class.

2. TB1: Pg 50-2.8

3. Material: Pg 39-1.13

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

2. Give the structure of a C program along with the examples. (Nov, 15)( MP-1)

Answer:

1. from notes given in the class.

2. TB1: Pg 48-2.6

3. Material: Pg 10-1.11

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

3. What is the purpose of main function? (Nov, 14)

The function main( ) invokes other functions within it. It is the first function to be called when the
program starts execution. It is the starting function. It returns an int value to the environment that
called the program

4. What do you mean by scope of a variable? Explain in brief. What is the difference between ‘p’
and “p”? (Nov, 14)

Answer:

1. from notes given in the class.

2. TB1: Pg 229-6.7.2(First paragraph), Pg288-7.9 (Second paragraph)

Scope of a variable

The region of the program over which the declaration of an identifier is accessible is called the scope
of the identifier.

The scope relates to the accessibility, the period of existence, and the boundary of usage of variables
declared in a program.

Scopes can be of four types.

i. block ii. File iii. Function iv. function prototype.

Difference between ‘p’ and “p”

Character constants are written between single quotes.

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

String constants are written between double quotes.

For example, “acd” is a character array of size 4, with the last element being null character \0. For
example, “a” and ‘a’ are not the same. The “a” have two elements, the first with value ‘a’ and the
second with the value ‘\0’.

5. Why is data type specified for a variable declaration and how can value be assigned to
variables?(MP-1)

Answer:

1. from notes given in the class.

2. TB1: Pg 88-Q6, Pg 63-2.12.4

3. Material: Pg 18-1.7.1, 1.7.3, differences

The type, or data type, of a variable determines a set of values that the variable might take and a set
of operators that can be applied to those values.

Using assignment operator (=) values can be assigned to variables declared.

General form, of assignment operator is

variable_name=expression;

Examples:

i=6;

i=i+1;

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

6. What is meant by user defined data type? Write a C program which uses user-defined data type.
(MP-2)

Answer:

1. from notes given in the class.

2. TB1: Pg50-Fig 2.7

3. Material: Pg 41-1.13.3

Sometimes, the basic set of data types defined in the C language such as int, float etc. may be
insufficient for your application. In circumstances such as these, you can create your own data
types which are based on the standard ones know as user defined data types.

There are three mechanisms for doing this in C:

 using typedef
 using structures
 using unions

/* write any program of structures or unions concept*/

7. Define variable (Nov,16)

Answer:

1. from notes given in the class.

2. TB1: Pg 49-Fig 2.7

3. Material: Pg 38-1.12

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

MODULE-2
PART-2A: TOKENS
1. Write a short notes on operators available in C-language along with their precedence ad
associativity rules. (Nov, 15)(MP-2).

Answer:

1. From notes given in the class.

2. TB1: Pg 65-2.13.

2. Write a program to print the reverse of a number. (Nov, 15)(Nov, 14)

#include <stdio.h>

int main()
{
int n, reverse = 0;
printf("Enter a number to reverse\n");
scanf("%d", &n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("Reverse of entered number is = %d\n", reverse);
}

3. Write a C program to read a floating point number. Display the right most digit of the integral
part of the number.(Nov,15)

#include<stdio.h>
#include<conio.h>
main()
{
int a,e;
float p;
printf("Enter the value of p\n");
scanf("%f",&p);
a=int(p);
printf("%d\n",a);
e=a%10;
if(a>10)
printf("%d\n",e);
}

4. What are the constants supported by C language? Explain with an example for each (MP-1)
Answer:

1. From notes given in the class.

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

2. TB1: Pg 61-2.12.3

5. What is casting? Explain automatic and explicit type casting with suitable examples. (MP-1)
(MP-2) (Nov,16)

Answer:

***read answer form notes

1. From notes given in the class.

2. TB1: Pg 78-2.16(only for reference)

PART-2B: INPUT AND OUPUT


1. “Formatted input and output functions are very helpful for programmers”-justify your answer
with examples. (MP-1)

Answer:

1. From notes given in the class.

2. TB1: Pg 100-3.4

2. What are different formatting specifications of printf and scanf? (Nov, 14)(Nov,16)

Answer:

1. From notes given in the class.

2. TB1: Pg 100-3.4, Table 3.1

PART-2C: CONTROL STATEMENTS


1. Explain the importance of a switch case statement. In which situations is a switch case
desirable? Also give its limitations. (Nov, 15)(MP-2)

Answer:

1. From notes given in the class.

2. TB1: Pg 133-4.4.3

2. How continue differ from break? (Nov, 13)

Answer:

1. From notes given in the class.

2. TB1: Pg 158-Tale4.8, Pg 164-Q6.

3. Explain various control structures with an example. (Nov, 13)

Answer:

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

1. From notes given in the class.

2. TB1: Pg 124-4.4.1

4. What is two-way decision statement? Explain and draw its flow symbol. (MP-1)

Answer:

1. From notes given in the class.

2. TB1: Pg 125-Two way decision using if-else statement

5. Write a C program to read a number and check whether it is eve or odd using goto statement.
(MP-2)

#include<stdio.h>
main()
{
int y;
printf("\n Enter any value : ");
scanf("%d",&y);
if(y%2==0)
goto even;
else
goto odd;
even:
printf("\n %d is an Even Number :",y);
return;
odd:
printf("\n %d is an Odd Number ",y);
}

6. Compare the use of if-else construct with that of ternary operator (Nov.16)

Answer:

if (expression)
{
Block of statements;
}
else
{
Block of statements;
}

1. From notes given in the class

2. Material Pg 13-6

7. What are the unconditional branching statements available in C? Explain in detail (Nov, 16)

Answer: 1. From notes given in the class

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

MODULE-3
PART-3A: LOOPS
1. Write a short note on iterative statements that C language supports. (Nov, 15)

Answer:

1. From notes given in the class.

2. TB1: Pg 137-Introduction, Fig 4.7, Table 4.7, Pg 138-4.5.1,Pg 143-4.5.2 ad Pg 151-4.5.3---

Little theory , syntax and example program only

2. Write a C program to check whether the given string is palindrome or not. (Nov, 15)

Answer:

1. From notes/ observation given in the class.

2. TB1: Pg 197.

3. Write a program to print the following pattern. (Nov, 15)

***

*****

#include<stdio.h>

main()

inti,j,k,n;

printf("\n Enter the limit : ");

scanf("%d",&n);

printf("\n\n");

for(i=n;i>0;i--)

for(k=i;k>0;k--)

printf(" ");

for(j=0;j<(n-(i-1));j++)

printf("%2c",'*');

printf("\n");

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

4. Differentiate between do-while loop ad while-do loop with the help of an example.(Nov, 14)
(Nov,16)

Refer Q1

5. Write a program to calculate sum of first even numbers taking n as input. (Nov, 14)

#include<stdio.h>

main()

int n,i=0,s=0;

printf(“enter a number\”);

scanf(“%d”,&n);

while(i<=n)

s=s+i;

i=i+2;

printf(“sum of even numbers is %d”, s);

6. Compare iteration and recursion with the help of an example. (Nov, 14)(MP 2)

Answer:

1. TB1: Pg 241-6.10.3

7.-------

8. Differentiate between iterative and repetitive executions. (MP-1)

Answer:

Refer Q1

9. Draw flow charts and write syntaxes of both for and while loops (MP-1)

Answer:

Refer Q1.

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

10. Distinguish between while, for and do-while constructs in C. (MP-2)

Answer:

Refer Q1.

11. Write a C program to calculate the sum of even numbers and odd numbers from 1 to n. Read
the value of n from user. (MP-2)

#include <stdio.h>
void main()
{
int i, num;
int odd_sum = 0, even_sum = 0;
printf("Enter the value of num\n");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if (i % 2 == 0)
even_sum = even_sum + i;
else
odd_sum = odd_sum + i;
}
printf("Sum of all odd numbers = %d\n", odd_sum);
printf("Sum of all even numbers = %d\n", even_sum);
}

12. Explain nested loops syntaxes with suitable examples

Answer:

1. From notes given in the class.

2. TB1: Pg 151-4.9

PART-3B: ARRAYS & STRINGS


1. Discuss about the declaration and initialization of 2-D dimensional array in C language. (Nov, 15)

Answer:

1-Dimesional

1. From notes given in the class.

2. TB1: Pg 170-5.2

2-Dimensional

1. TB1: Pg 199-5.4.1 and 5.4.3

2. Write a C program to multiply two 2-D matrices and display the result.(Nov, 14)(Nov,16)
Answer:

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

1. From notes/ observation given in the class.

2. TB1: Pg 204-Matrix Multiplication

3. How multi-dimensional arrays are declared and initialized I C language? Explain with a suitable
example. (Nov, 13)(MP-1)

Answer

TB1: Pg 199-5.4

4. Write a C program to read 3x3 matrix and calculate the sum of its diagonal elements.(MP-2)

*** Trace: Sum of diagonal elements of a square matrix

#include<stdio.h>
main()
{
int a[10][10],s,i,j,r,c;
printf("Enter the order of the matrix\n");
scanf("%d%d",&r,&c);
printf("Enter the values\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nThe matrix is\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
s=0;
if(r==c)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
s=s+a[i][j];
}

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

}
printf("\nSum of diagonal elements = %d",s);
}
else
printf("\n No diagonal elements");
printf("\n");
}

6. Write a C program to search an element using linear search and binary search.

Answer:

Linear Search

TB1: Pg178-Searching an element within an array.

Binary Search

TB1: Pg 180-Example 3 code

7. Write a C program to sort n elements in an array.

Answer

TB1: Pg178- Sorting array (Bubble sort program-pg 179)

8. Write a program to print the following pattern: (Nov, 16)

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,l,n;
clrscr();
printf("enter the range=");
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n-i;j++)
{
printf(" ");
}

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(l=i-1;l>=1;l--)
{
printf("%d",l);
}
printf("\n");
}
getch();
}

9. Discuss about string handling functions (Nov, 16)

Answer

1. From notes given in the class.

2. TB1: Pg 191-5.3.6

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

MODULE-4
PART-4A: FUNCTIONS
1. Write short notes on storage classes. (Nov, 15)(Nov, 14)(Nov, 13)(MP-2)

Answer:

1. from notes given in the class.

2. TB1: Pg 231-6.8.

2. Differentiate between call-by-value and call-by-reference using suitable examples (Nov, 15)

Answer:

1. from notes/observation given in the class.(Swapping of two numbers).

2. from material.

3. Write a program to compute factorial of a number using recursion? Can this be done via
iteration? (Nov, 14)(MP-2)(Nov,16)

#include <stdio.h>
int multiplyNumbers(int n);

int main()
{
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
}
long int multiplyNumbers(int n)
{
if (n >= 1)
return n*multiplyNumbers(n-1);
else
return 1;
}
4. Write a function to print n prime numbers taking n as input? (Nov, 14)

#include <stdio.h>
int checkPrimeNumber(int n);
int main()
{
int n1, n2, i, flag;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
// i is a prime number, flag will be equal to 1

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

flag = checkPrimeNumber(i);
if(flag == 1)
printf("%d ",i);
}
return 0;
}
// user-defined function to check prime number
int checkPrimeNumber(int n)
{
int j, flag = 1;
for(j=2; j <= n/2; ++j)
{
if (n%j == 0)
{
flag =0;
break;
}
}
return flag;
}

5. What is recursion? Explain with an example. (Nov, 13)(MP-2)

Answer:

1. TB1: Pg 235-6.10.1. Example- Refer Q3.

2. from material.

6. Define function? Write the advantages of function? Explain function definition. (Nov, 13)(MP-1)

Answer:

1. TB1: Pg 215-6.2, 6.2.1 and Pg 216-6.3.1, Pg 217-6.3.2

2. from material.

7. What are different types of variables based on its storage type and scope? (Nov, 13)(MP-2)

Answer:

Refer-Q1

8. Write a program to solve the Towers of Hanoi using recursion (MP-1)

Answer:

1. TB1: Pg 237

9. Explain different categories of functions with examples

Answer:

1. from notes given in the class(Classification of basic function designs are by their return

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

values and their parameters list)

2. from material.

3. TB1: Pg 221-6.5

PART-4B: POINTERS
1. What is void pointer? Explain with an example. (Nov, 15)(Nov, 14)

Answer:

1. from notes given in the class.

2. TB1: Pg 278-7.5.

3. RF1: Pg 267-7.6(Generic pointer)

2. Explain the term dynamic memory allocation. Specify the functions used for dynamic memory
allocation along with suitable examples. (Nov, 15)

Answer:

1. from notes given in the class.(summarized answer with examples)---read from here

2. TB1: Pg 320-7.17.

3. RF1: Pg 287-7.2

3. What do you mean by null pointer? (Nov, 14)

Answer:

1. from notes given in the class.

2. TB1: Pg 278-7.6.

3. RF1: Pg 266-7.5

4. Write a program to swap the values between two variables using pointers (Nov, 14)

Answer:

1. from notes/observation given in the class.

2. TB1: Pg 280

5. Discuss about pointer dangling? (Nov, 13)(MP-1)(Nov, 14)

Answer:

1. TB1: Pg 333-Dangling pointer in C

2. RF1: Pg 292-Dangling Pointer

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

6. Write a C program to sort given n cities by using pointers. (Nov, 13)

Answer:

*** Answer is to sort strings in dictionary or alphabetical order using pointers.

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char *x[20];
int i,n=0;
void reorder(int n,char *x[]);
clrscr();
printf("Enter no. of String : ");
scanf("%d",&n);
printf("\n");

for(i=0;i<n;i++)
{
printf("Enter the Strings %d : ",i+1);
x[i]=(char *)malloc(20*sizeof(char));
scanf("%s",x[i]);
}
reorder(n,x);
printf("\nreorder list is : \n");
for(i=0;i<n;i++)
{
printf("%d %s\n",i+1,x[i]);
}
getch();
}
void reorder(int n,char *x[])
{
int i,j;
char t[20];
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(x[i],x[j])>0)
{
strcpy(t,x[j]);
strcpy(x[j],x[i]);
strcpy(x[i],t);
}
return;
}

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

7. How to declare a pointer to constant? Give an example. (MP-1)

Answer:

1. TB1: Pg 334-7.20.1

8. What are the differences between calloc() and malloc()? (MP-1)

Answer:

Refer Q2.

9. How a 2-D array can be accessed through a pointer? Explain. (MP-2)

Answer:

1. TB1: Pg 307-Intro and Pg 309-7.14.1.

10. Write a C program to read a 2D matrix of order 3x3 and calculate its transpose using pointers
(MP-2)

***Search in the net.

11. Write a C program to perform various arithmetic operations using pointers. (Nov, 16)

Answer:

1. from notes/observation given in the class.

12. What is an array of pointers? How is it different from a pointer to an array? (Nov, 16)

Answer:

1. from notes given in the class.

13. How do we pass an array to a function? Explain with an example program (Nov, 16)

Answer:

1. from notes given in the class.

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

MODULE-5
PART-5A: STRUCTURES
1. Explain the utility of “ typedef ” keyword in structures. (Nov, 15)

Answer:

1. TB1: Pg 361-8.2.5

2. RF1: Pg 310-8.1.2

2. What is a self referential structure? How can an individual structure member be accessed in
terms of its corresponding pointer variable? (Nov, 14)

Answer:

1. RF1: Pg 327-8.5

3. Create a structure to specify data on students as given below: Roll No, Name, Department,
Course and Year of admission. Assuming there are not more than 200 students in the college.
Write a program to print names who have joined last year. (Nov, 14)

Answer:

1. From notes.

2. From Let us C by Y Kanethkar

4. Explain nested structures with an example. (Nov, 13)

Answer:

1. TB1: Pg 362-8.2.6

2. RF1: Pg 314-8.2

3. from notes/observation given in the class.

5. What is a structure? How is it different from an array? (MP-1) (Nov,16)

Answer:

1. TB1: Pg 351-8.2 and 8.2.1

2. RF1: Pg 308-8.1 and 8.1.1

3. from notes/observation given in the class.

6. Write a C program to create a student profile consisting of name, father’s name, roll number
and marks as a structure. Determine the student who scored maximum marks. (MP-2)

Answer:

1. From notes.
PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE
SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

7. Is it possible to create an array of structures? Explain with the help of an example (Nov, 16)

Answer:

1. From notes.

2. TB1: Pg 363-8.2.7

PART-5B: UNIONS
1. Compare structure with union with an example. (Nov, 15)(Nov, 14)(Nov, 13)(MP-1)(MP-2)

Answer:

1. From notes/material.

2. TB1: Pg 372-8.3.3

PART-5C: FILES
1. Write short notes on functions that are used to:

a) Read data from a file.

b) Write data to a file. (Nov, 15)

Answer:

1. From material.

2. RF1: Pg 348-9.3.4 and Pg 351- 9.4.4

2. What is a file? Explain the terms file pointer ad EOF with suitable examples. (Nov, 15)

Answer:

1. From notes/material.

2. TB1: Pg 390-9.2.1 and Pg 394-9.3.2

3. What is the difference between fscanf() and fread() in C.(Nov, 14)

Answer:

1. From notes/material.

2. RF1: Pg 348-9.3.4 and Pg 346-9.3.1

4. Write a program to read a file and display its contents along with line numbers before each line.
(Nov,14)

****create a file name hello.c and write some text in that

#include<stdio.h>
main()

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

{
FILE *fp;
char ch;
int i=1;
fp=fopen("hello.c","r");
if(fp==NULL)
{
printf("can't open source file");
exit(1);
}
printf("%d",i++);
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
{
break;
}
printf("%c",ch);
if(ch=='\n')
{
printf("%d",i);
i++;
}
}
fclose(fp);
}

5. Explain various file operations of C by giving syntax of each operation. (Nov, 13)(MP-2)

Answer:

1. From notes/material.

6. Write a C program to store student details in a file by using record concept.(Nov, 13)

Answer:

1. RF1: Pg3 62- Q16

7. What is a file? Explain various file opening modes. (MP-1)

Answer:

1. From notes/ material

2. TB1: Pg 391 – Table 9.1

3. RF1: Pg 344- File mode

8. What are the functions we use to read and write a text file? Explain each one. (MP-1)

Answer:

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

1. TB1: Pg 393-9.3

9. Write a C program to append the contents of a file to an existing file. (MP-2)

#include<stdio.h>
main()
{
FILE *fp1,*fp2;
char ch,fname1[20],fname2[20];
printf("\n enter source file name");
gets(fname1);
printf("\n enter destination file name");
gets(fname2);
fp1=fopen(fname1,"r");
fp2=fopen(fname2,"a");
if(fp1==NULL||fp2==NULL)
{
printf("unable to open");
exit(0);
}
do
{
ch=fgetc(fp1);
fputc(ch,fp2);
}while(ch!=EOF);
fclose(fp1);

fclose(fp2)
}

9. Write a C program to copy the contents of one file into another.

Answer:

1. TB1: Pg 397-Q7

10. Write a C program that accepts the name of two files. It should copy the first file into the
second line by line. Use fgets() and fputs() functions.

Answer:

1. TB1: Pg 398-Q8

11. Write a program to read the details of a student and then print it on the screen as well as write
it into a file (Nov, 16)

Answer:

1. TB2: Pg 359-Q11

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE


SUPPORTING HAND BOOK OF EID101: PROGRAMMING IN C for 1/4 B8 (2017 - 2018 AB)

12. Write a short note on the following functions. For each function, give a program code that
demonstrates it usage i) fopen() ii) fclose()

Answer:

1. From notes/material.

2. TB2: Pg 391,392 -9.2.2,9.2.3

*****ALL THE BEST*****

PREPARED BY VIKAS B, ASSISTANT PROFESSOR, DEPT. of CSE

Das könnte Ihnen auch gefallen