You are on page 1of 13

UNIT I

INTRODUCTION TO COMPUTER
PART A
1. What is the difference between Compiler and Interpreter
Compiler Interpreter
Compiler Takes Entire program as input Interpreter Takes Single instruction as input .
Errors are displayed for every
Errors are displayed after entire program is checked
instruction interpreted
Intermediate Object Code is Generated No Intermediate Object Code is Generated
Conditional Control Statements are
Conditional Control Statements are Executes faster
Executes slower
Memory Requirement is More Memory Requirement is Less
Every time higher level program is converted into
Program need not be compiled every time
lower level program
Example : C Compiler Example : BASIC

PART B
1. What is a flowchart?Discuss various symbols used in flowchart.Illustrate with an example.
Page Number : 5,6
2. Explain the step in program development.
Page Number 4,5,6

INTRODUCTION TO C
PART A
1. Distinguish between variable and constant.
Page Number : 10
2. Describe type casting with example
Page Number : 16
3. Explain type conversion.Explain Implicit and Explicit type conversion
Page Number : 16
4. Give the list of Bitwise operators of C
Page Number : 12,13
5. Distinguish between while and do while statements in C
Page Number : 23(table) and syntax of while and do while(23,24)
6. Discuss briefly about goto statement
Page Number : 21,22
7. What precautions should be taken while constructing statements in C language
Each statement in C is terminated or separated by ;
Block of statements should be enclosed in Curly braces {…}
Selection statement such as Switch must have unique Case labels and it’s better to have a Default
case and a Break Statement with every case.
Iterative statements must eventually become false and never put a semicolon after the condition.
8. Give any two restriction to Conditional Operator
Its a ternary operator pair “?:” It takes three operands Expression 1? Expression 2 : Expression 3
If Expression 1 is true then Expression 2 is output
If Expression 1 is false then Expression 3 is output
Example : To find the greatest A=10 B=5 (A>B)? A : B gives A as output as A>B is true.
Restrictions:
 If datatypes of values are simple them the type of result is the larger of the type exp2 or exp3.
 Do not mix user defined datatypes with simple datatypes
 Do not mix variables with pointers

PART B
1. State and Explain varies identifier in C Program.
Page Number : 9
2. Describe various types of operator used in C.
Page Number : 11,12,13
3. Explain Bitwise operator with suitable example
Page Number : 12,13
4. Write briefly notes on Precedence and Associativity.And also discuss about operator
Precedence in expression evaluation with suitable example.
Page Number : 15
5. Explain various decision making statement used in C. Give example
Page Number : 17,18,19,20,21
6. Explain Control statements in C language
Page Number : 17 - 25
7. Explain with a sample program about while,for,do while and switch statement in C
Page Number : 20,23,24
8. With the help of an example Explain the usage of break and continue.
Page Number : 24
9. Write C Program to print prime numbers between 1 to n.
for(i=2;i<=n;i++)
#include<stdio.h> {
#include<conio.h> c=0;
void main() for(j=1;j<=i;j++)
{ {
int i,j,n,c; if(i%j==0)
clrscr(); c++;
printf("Enter the value of n:"); }
scanf("%d",&n); if(c==2)
printf("%d",i);
}
getch();
}
10. Write a C Program to read a set of n single digits and convert them into single decimal integer.
Example: Digits [ 1,2,3] to Integer 123
#include<stdio.h>
#include<conio.h>
void main()
{
int digits , integer=0;
while(digits!=’\n’) // reads digits and converts
{
digits=getchar();
if(digits = = ‘\n’)
break;
integer = ( integer + ( digits – ‘0’))*10; // -0 in order to get the actual number
}
integer = integer/10;
printf(“Integer : %d”, integer);
}
If user input 123 then
integer = (1)*10; //10
integer = (12)*10; //120
integer = (123)*10; //1230
integer = (1230)/10; //123
UNIT II

FUNCTIONS
PART A
1. What is inter function communication
Page Number :
2. What are the scope rules
Page Number :
3. What is the use of type qualifiers
Page Number :
4. List down the limitations of recursions
Page Number :
5. Is it better to use macro or function
The choice between using a macro and a function is deciding between the tradeoff of faster program
speed(use macro) versus smaller program size(use function)
Macros have the advantage of being more faster than functions .But code could be somewhat larger
when you use macros than if you were to use functions.

PART B
1. What is function Parameter? Explain different types of parameters in C functions
Page Number :
2. Explain difference between Call by value and Call by reference with example
Page Number :
3. What is Storage class? Explain various storage classes
Page Number :
4. Explain difference between static external and simple external variable. Write a C Program to
illustrate the properties of static variable
Page Number :
5. Explain Preprocessor commands with example
Page Number :
6. Write Factorial program using Recursion and Non recursion (Iterative)
Page Number :

ARRAYS
PART A
1. Why is it necessary to give the size of an array in an array declaration
No, It is not necessary to give the size of an array.
You can type blank brackets (int a[ ]) when declaring the array,
If you omit the size of the array, an array just big enough to hold the initialization is created.
int a [ ] = {5,6,7};
2. Write the array applications
Page Number :

PART B
1. What is an array? Explain declaration and Initialization of 1D, 2D and 3D array with example
Page Number :
2. Explain with example how to pass array to a function
Page Number :
3. Write a C Program to find product of 2 n*n matrices (Multiplication of matrices)

4. Write an algorithm that would check whether the elements in a given array are distinct or not.
Step 1 : Start
Step 2 : Read elements in the array
Step 3 : Select the first element of the array
Step 4 : Compare the element of the array with the elements following it.
Step 5 : If the value is found to be same then Array is not distinct.
Step 6 : Else select the next element and Repeat from step 4 until we reach the end of the list
Step 7 : If no two elements have same value then Array is found to be Distinct.
Step 8 : Stop

Write a C Program to delete duplicate from Write a C Program that reads values from
an array of integer keyboard into 2D array.
Create two 1D array that contains row and
#include<stdio.h> column average.
void main()
#include<stdio.h>
{
#include<conio.h>
int arr[20], i, j, k, size; #define r 3
printf("\nEnter array size : "); #define c 4
scanf("%d", &size); void main()
printf("\nAccept Numbers : "); {
for (i = 0; i < size; i++) int mat[r][c], matr[r],matc[c],i,j,n;
scanf("%d", &arr[i]); printf(“Enter the values in 2D array:”);
for(i=0; i<r; i++)
printf("\nArray with Unique list  : ");
{
for (i = 0; i < size; i++) for(j=0; j<c; j++)
{ {
for (j = i + 1; j < size;) scanf(“%d”,&mat[i][j]);
{ }
if (arr[j] == arr[i]) }
{
for (k = j; k < size; k++) for (n=0; n< r ; n++)
{
{
int sum = 0;
arr[k] = arr[k + 1]; for (i=0;i<c;i++)
} sum=+mat1[n][i];
size--; matr[n]=sum/c;
} }
else for(i=0; i<r; i++)
j++; printf(“%d”,matr[i]);
}
for (n=0; n< c ; n++)
} {
for (i = 0; i < size; i++) int sum = 0;
{ for (i=0; i<r; i++)
printf("%d ", arr[i]); sum=+mat1[i][n];
} matc[n]=sum/r;
} }
for(i=0; i<c; i++)
printf(“%d”,matc[i]);

getch();
}
UNIT III

POINTERS
PART A
1. What is the difference between Array and pointer
Page Number : 47
2. Write brief notes on Memory Allocation Functions
Page Number : 59
3. Describe features of Pointers
Execution time with pointer is faster
Pointers save memory space.
Pointers is used for dynamic memory allocation
Pointer is used for handling array, Structures and Files.
Pointer allows references to function and thereby helps in passing of function as argument.

PART B
1. Write a program to swap two numbers using pointers
Page Number : 52
2. Discuss various applications of pointers
Page Number : 54 - 60
3. Explain Pointer Arithmetic
Page Number : 54-56
4. What are the Arithmetic Operators that are permitted on Pointers
The arthimetic operation permitted on Pointers are :
If p is pointing to char whose address is 100 and p1 is 102
Name Operator Example
Incrementing Pointer ++ p++
the address of p will be 101
Decrementing Pointer -- p- -
the address of p will be 99
Addition of Pointer and Number + p+10
the address of p will be 110
Subtraction of Pointer and Number - p-10
the address of p will be 90
Differencing between two pointers - p2-p1
Returns number of elements that are there between them
Comparing two Pointers <,>, p1< p2
== compares the addresses

The operators that are not permitted are addition of two pointers , multiplication and division of
pointers
5. Discuss the need of pointer to function.
6. Discuss dynamic memory management with pointers
Page Number : 57 - 60

STRINGS
PART A
1. Explain how strings are declared and initialized in C
Page Number : 63, 64
2. Are the following two statements identical
char str[6]=”kicit”;
char *str =”kicit”;
No! Arrays are not Pointers.
The array declaration char str[6] ; requests that space for 6 characters be set aside, to be known
by name str.
The pointer declaration char *str ; on the other hand, requests a place that holds a pointer, to be
known by the name str.
3. Describe array of string
Page Number : 64, 65
4. Mention various string manipulation function in C
Page Number : 70 - 77
5. What is the use of strspn function.
Page Number : 76
6. With an example Explain the function to calculate string length (strlen)
Page Number : 70

PART B
1. Write a function that counts the number of characters and lines in a program
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
int c=0,l=0,w=0;
char ch;
clrscr();
printf("Enter the text at the end press #: ");
scanf("%c",&ch);

do
{
scanf("%c",&ch);
c++;
if(ch= =' ');
w++;
if(ch=='\n')
{
l++;
w++;
}
}while(ch!='#');

printf("\n Numbers of characters=%d",c);


printf("\n Numbers of words=%d",w+1);
printf("\n Numbers of lines=%d",l+1);
getch();
}

2. List any for library functions for string manipulation


Page Number : 70-76
3. State and Explain with a sample program various string manipulation functions
Page Number : 70-76
4. Write a function that alerts two strings str1, str2 as arguments and find which of the two is
alphabetically greater. The function should return 1 if str1 is greater than str2
0 if str1 is equal to str2 and -1 if str1 is less than str2
#include <stdio.h>
#include <string.h>
 void main()
{
char str1[100], str2[100];
  printf("Enter the first string\n");
gets(str1);
  printf("Enter the second string\n");
gets(str2);

  if (strcmp(str1,str2) > 0)
  printf("str1 is greater than str 2.\n");
else if (strcmp(str1,str2) == 0)
printf("Entered strings are equal. \n");
else if (strcmp(str1,str2) < 0)
printf("str1 is less than str 2.\n");
}

5. Write a C Program that replace a substring with a new string


#include <stdio.h>
#include <string.h>
void main()
{
char mystr[] = "##this is##a examp#le";
puts(mystr);
puts(replace(mystr, '#', '*'));
}

char *replace(char *s, char old, char new)


{
char *p = s;
while(*p)
{
if(*p == old)
*p = new;
++p;
}
return s;
}

6. Write a C Program to reverse the string passed as an argument that cannot be altered.
#include <stdio.h>
#include <string.h>
 void main()
{
char str1[100], str2[100];
  printf("Enter the first string\n");
gets(str1);
  str2 = strrev(str1);
printf("%s",str2);
}

7. Write a C Program that would accept a string of any number of characters.Provides the
function to count the number of vowels in the given string.
#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
int vowels = 0, i = 0;
clrscr();
printf(“ENTER A STRING…: “);
gets(str);
while(str[i] != ‘\0′)
{
if(str[i]==’A’ || str[i]==’E’ || str[i]==’I’ || str[i]==’O’ || str[i]==’U’ )
vowels++;
i++;
}
printf(“THE TOTAL NUMBER OF VOWELS IS…: %d”, vowels);
getch();
}

8. Write a program which will read a string and rewrite it in alphabetical order.
For example STRING should be written as GINRST.
main()
{
char str[100],temp;
int i,j;
clrscr();
printf(“Enter the string :”);
gets(str);

for(i=0; str[i]!=’\0’ ; i++)


{
for(j=i+1 ; str[j] !=’\0’ ; j++)
{
if(str[i] > str[j])
{
temp=str[j];
str[j]=str[i];
str[i]=temp;
}
}
}
printf(“%s ”, str);
getch();
}

9. Write function in C using pointers that would get an input string and compress it’s length
UNIT IV

ENUMERATED, STRUCTURE AND UNION TYPE


PART A
1. Write a short note on typedef and Enumerated.
Page Number : 80
2. What is meant by Enumerated data type
Page Number : 80,81
3. Define Structure
Page Number : 82
4. What is Self referential structures. How it differs from Nested structures
Page Number : 92,86
5. Discuss about Bitfields
Page Number : 91
6. Write brief notes on Union
Page Number : 93
7. Give the difference between Structure and Unions
Page Number 93

PART B
1. Explain about declaration,Initialization,accessing of structures.And also discuss about
Complex structures
Page Number : 82-83, 85-87
2. Explain Array of pointers with example.
Page Number : 65
3. Write a program to illustrate the usage of Command line arguments
Page Number : 92
4. Write a program to handle students profile data using structure
#include <stdio.h>
struct student{
char name[50];
int roll;
float marks;
};
void main(){
struct student s;
printf("Enter information of students:");
printf("Enter name, rollno , marks : ");
scanf("%s %d %f ", s.name , &s.roll , &s.marks);
printf("Displaying Information");
printf("Name , Roll , Marks : %s %d %f ", s.name, s.roll , s.marks);
}

5. Define as structure called salary another structure called allowance. Use the structure variable
allowance in salary structure. Write program to read data into the structure variables.
6. Write a recursive function that would scan the created structure array and print the complete
date , day,month ,year information if the data is even number
7. With the help of Example Explain Union of Structures
Definition : Union
Union is collection of elements of same or different type storedStructure Structure
in same memory location.
The element of the union will be structure.
Example :
Declaring a new datatype ie union of structures :
There are two steps : first declare the structures and then the union containing them.
1. Declaring structures: 2.Declaring Union of structure
Declare 1st Declare 2nd
structure structure union college
struct student struct staff {
{ { struct student x;
int roll-no ; int id; struct staff y ;
char grade float salary; };
}; };

union college z
student x staff y
rollno grade id salary

 Declaring variable : union college z;


 Initializing fields : z.x.rollno = 7;
z.x.grade = ‘A’;
 Accessing rollno : z.x.rollno ;
Same memory location is used to store one of the elements at a time either student x or staff y
Memory allocated should be large enough to store the biggest element of union
FILES
PART A
1. What are File input and Output functions
Page Number : 99, 100
2. Compare Text file with Binary file
Page Number : 97
PART B
1. What are file stream?Discuss about state of file, Opening and Closing file
Page Number : 95-96 , 98
2. Write a short notes on Random access file function or
What are the ways to set the file pointer randomly in file or
Discuss File positioning functions in C
Page Number : 101
3. List and Explain stream functions for Binary files along with their prototypes
Page Number : 100

Write a C program to copy contents of one Write a program that reads a file containing
file to another file. integers and appends at its end the sum of all.

#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
#include<process.h> #include<process.h>

void main() void main()


{ {
char ch; int a,i,n,sum=0;
FILE *fp1,*fp2; FILE *fp;
clrscr();
fp=fopen(“DATA”,”w”); ////Writing numbers to the file
fp1=fopen("file1.txt","w"); printf(“How many numbers?”);
printf("\n Enter the contents into file1:"); scanf(“%d”,&n);
while((ch=getchar())!='^') printf(“Enter numbers in the file:n”);
putc(ch,fp1); for(i=0;i<n;++i)
fclose(fp1); {
scanf(“%d”,&a);
fp1=fopen("file1.txt","r"); putw(a,fp);
fp2=fopen("file2.txt","w"); }
while((ch=getc(fp1))!=EOF) fclose(fp);
putc(ch,fp2);
fclose(fp1); fp=fopen(“DATA”,”r”); // Reading the file and doing
fclose(fp2); sum
while((a=getw(fp))!=EOF)
fp2=fopen("file2.txt","r"); sum+=a;
printf("\n The contents of file2:"); fclose(fp);
while((ch=getc(fp2))!=EOF)
printf("%c",ch); fp=fopen(“DATA”,”a”); //Appending sum to the file
fclose(fp2); putw(sum,fp);
fclose(fp);
getch();
} printf(“File after append:”);
fp=fopen(“DATA”,”r”); //Displaying file after append
while((a=getw(fp))!=EOF)
printf(“%d “,a);
fclose(fp);

getch();
}

UNIT V

SEARCH AND SORT


PART A
1. What is Binary Search
Page Number : 108
2. Why Binary Search is preferred over Linear Search
Binary Search ignores half of the elements just after one comparison thus reducing the time
complexity to O(log n)
Linear Search Binary Search
It does not expect the list to be sorted It expects the list to be sorted
The key to be searched is compared The key to be searched is compare key with a[mid]
with all element of list one by one. case a : if key == a[mid]  Key is found
If match exists, the search is case b : if key < a[mid]  Search in 1st half of list
terminated. case c : if key > a[mid]  Search in 2nd half of list
i.e It ignores half of the list just after one comparison
The time complexity is O(n). The time complexity is O(Log n).
It sorts the list and reduces the time complexity.

PART B
1. What is Selection Sort and Illustrate using an example.
Write a C program to sort the list of integers using Selection sort.
Page Number : 103-105 , program
2. Explain Bubble Sort with suitable example.
Page Number : 106,107
3. Write a C program for Binary Search
4. Sort the following 10 elements using Bubble sort technique and Compare it with insertion sort
technique.How many passes for each technique
87, 54,98,34,27,88,36,12,90,23
5. Explain Quick Sort.

SINGLY LINKED LIST


PART A
1. List down any three applications of Linked list
Page Number : 120
2. List the stack operations
Page Number : 120
3. Define queue.Give its representations
Page Number : 134
4. Describe the Dequeue operations
Page Number : 130 , 133
5. How will you find that the singly linked list is in circular state.

PART B
1. Explain Singly linked list implementation
Page Number : 112 - 120
2. What is Stack . Explain its applications
Page Number : 120 - 126
3. Write a C program to implement Queue using array or
Write a C program to perform insertion and deletion operation in a Queue.
Page Number : 131
4. Discuss the advantages of Linked list over Arrays
5. With a neat diagram Explain the operations performed in Doubly linked List.

You might also like