Beruflich Dokumente
Kultur Dokumente
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.
Notes: hand written notes posted in the xlearn ad notes given in the class.
MODULE-I
Answer:
Algorithm:
Advantages:
Disadvantages:
Example:
Flowchart:
Advantages:
Disadvantages:
Example:
2. Write an algorithm and draw flowchart for finding the biggest among the given three numbers?
(Nov, 13)
Answer:
Algorithm:
1. START
3. INPUT A, B, C
THEN PRINT A
THEN PRINT B
ELSE
PRINT C
6. STOP
Flowchart:
Answer:
2. TB1: Pg 12-1.8.1.
3. Material: Pg 16-1.6.1
Top-down analysis breaks the whole problem into smaller logical tasks and defines the hierarchical
link between the tasks.
i. Define the complete scope of the problem to define the basic requirement for its solution.
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:
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:
Answer:
3. Material: Pg 3-1.2
Answer:
i. Preprocessor
ii. Compiler
iii. Linker
iv. Loader
Also write down the differences between compiler and interpreter. (Nov, 15)
Answer:
2. TB1: Compiler-Pg 6-1.3 and figure 1.7, Linker-Pg 7 1.3.2, loader- Pg 7-1.3.3
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 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
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:
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.
Properties of an Algorithm:
1. START
3. INPUT N
4. IF N=2 THEN
5. D :=2
7. R:=N-Q*D
9. D:=D+1
ELSE
PRINT “PRIME”
12. STOP
8. Define programming. Discuss about different types of programming languages (Nov, 16)
Answer:
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.
PART-1B: BASICS OF C
1. Write short notes on basic data types that the C-language supports. (Nov, 15)
(OR)
Answer:
2. TB1: Pg 50-2.8
3. Material: Pg 39-1.13
2. Give the structure of a C program along with the examples. (Nov, 15)( MP-1)
Answer:
2. TB1: Pg 48-2.6
3. Material: Pg 10-1.11
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:
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.
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:
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.
variable_name=expression;
Examples:
i=6;
i=i+1;
6. What is meant by user defined data type? Write a C program which uses user-defined data type.
(MP-2)
Answer:
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.
using typedef
using structures
using unions
Answer:
3. Material: Pg 38-1.12
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:
2. TB1: Pg 65-2.13.
#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:
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:
Answer:
2. TB1: Pg 100-3.4
2. What are different formatting specifications of printf and scanf? (Nov, 14)(Nov,16)
Answer:
Answer:
2. TB1: Pg 133-4.4.3
Answer:
Answer:
2. TB1: Pg 124-4.4.1
4. What is two-way decision statement? Explain and draw its flow symbol. (MP-1)
Answer:
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;
}
2. Material Pg 13-6
7. What are the unconditional branching statements available in C? Explain in detail (Nov, 16)
MODULE-3
PART-3A: LOOPS
1. Write a short note on iterative statements that C language supports. (Nov, 15)
Answer:
2. Write a C program to check whether the given string is palindrome or not. (Nov, 15)
Answer:
2. TB1: Pg 197.
***
*****
#include<stdio.h>
main()
inti,j,k,n;
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");
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;
6. Compare iteration and recursion with the help of an example. (Nov, 14)(MP 2)
Answer:
1. TB1: Pg 241-6.10.3
7.-------
Answer:
Refer Q1
9. Draw flow charts and write syntaxes of both for and while loops (MP-1)
Answer:
Refer Q1.
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);
}
Answer:
2. TB1: Pg 151-4.9
Answer:
1-Dimesional
2. TB1: Pg 170-5.2
2-Dimensional
2. Write a C program to multiply two 2-D matrices and display the result.(Nov, 14)(Nov,16)
Answer:
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)
#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];
}
}
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
Binary Search
Answer
#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(" ");
}
for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(l=i-1;l>=1;l--)
{
printf("%d",l);
}
printf("\n");
}
getch();
}
Answer
2. TB1: Pg 191-5.3.6
MODULE-4
PART-4A: FUNCTIONS
1. Write short notes on storage classes. (Nov, 15)(Nov, 14)(Nov, 13)(MP-2)
Answer:
2. TB1: Pg 231-6.8.
2. Differentiate between call-by-value and call-by-reference using suitable examples (Nov, 15)
Answer:
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
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;
}
Answer:
2. from material.
6. Define function? Write the advantages of function? Explain function definition. (Nov, 13)(MP-1)
Answer:
2. from material.
7. What are different types of variables based on its storage type and scope? (Nov, 13)(MP-2)
Answer:
Refer-Q1
Answer:
1. TB1: Pg 237
Answer:
1. from notes given in the class(Classification of basic function designs are by their return
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:
2. TB1: Pg 278-7.5.
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
Answer:
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:
2. TB1: Pg 280
Answer:
Answer:
#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;
}
Answer:
1. TB1: Pg 334-7.20.1
Answer:
Refer Q2.
Answer:
10. Write a C program to read a 2D matrix of order 3x3 and calculate its transpose using pointers
(MP-2)
11. Write a C program to perform various arithmetic operations using pointers. (Nov, 16)
Answer:
12. What is an array of pointers? How is it different from a pointer to an array? (Nov, 16)
Answer:
13. How do we pass an array to a function? Explain with an example program (Nov, 16)
Answer:
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.
Answer:
1. TB1: Pg 362-8.2.6
2. RF1: Pg 314-8.2
Answer:
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:
Answer:
1. From material.
2. What is a file? Explain the terms file pointer ad EOF with suitable examples. (Nov, 15)
Answer:
1. From notes/material.
Answer:
1. From notes/material.
4. Write a program to read a file and display its contents along with line numbers before each line.
(Nov,14)
#include<stdio.h>
main()
{
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:
Answer:
8. What are the functions we use to read and write a text file? Explain each one. (MP-1)
Answer:
1. TB1: Pg 393-9.3
#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)
}
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
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.