You are on page 1of 22

Do visit www.mritsece.co.

nr
www.mrits.co.nr

IMPORTANT PROGRAMS FOR EXTERNAL COMPUTER PROGRAMMING LAB EXAM

PART I
>Print Pascal triangle up to 7 rows.
>Generating prime numbers up to 100.
>Print the English alphabets A-Z and a-z using corresponding ASCII values.
>Program to find sum of individual digits of a number also check for Palindrome and Armstrong.
>Demonstrate Storage classes.
>Demonstrate Parameter passing mechanisms Call-by-value & Call-by-reference.
>Find Factorial of a number using Recursion.
>Generate Fibonacci series using Recursion.
>Calculate power of a number using Recursion.
>Find GCD of two numbers using Recursion.

PART II
>Implement a program to count number of characters, number of words, numbers of vowels and
consonants, number of numbers, number of lines and also blank spaces in a text using pointers.
>Implement a program to count number of characters, number of words, numbers of vowels and
consonants, number of numbers, number of lines and also blank spaces in a file.
>Implement a program to compute the monthly pay of 100 employees using each employee’s
name and basic pay. The DA is computed as 52% of the basic pay. Gross-salary (Basic +DA).
Print the employee’s name and Gross salary.
>Implement a program to open an pre-existing file and add information at the end of the file.
Display the contents of the file before and after appending.
>Compare the two structure variables.
>String comparison using pointers.
>Write a c program to read the text after skipping n characters from the beginning of the file.
>Sort the given names in alphabetical order.
>Implement a program to concatenate three names namely first name, second name and third
name into a single name to be called name.
>Addition and multiplication of two matrices.
>Transpose of a matrix.
>Test for upper triangular matrix.
>File copy program using command line arguments.
>To calculate subject wise and student wise total marks using structures.
>Implement a program that uses a structure to perform the operations reading a complex number,

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

writing a complex number, addition of two complex numbers and multiplication of two complex
numbers.
>Implement a program to accept records of different states using arrays of structures. Display the
state whose literacy rate is highest and whose income is highest.
>Implement a program to illustrate the method of sending an entire structure as a parameter to a
function with the help of finding quadratic equation roots.
>Find the length of the string using pointers.

PART III
>Implement Bubble sort or exchange sort
>Implement Selection sort or sort.
>Implement quick sort or Partition exchange sort.
>Implement Insertion sort.
>Implement Merge sort.
>Implement linear search.
>Implement Binary search.
>Convert Infix expression to Postfix expression.
>Evaluate Postfix expression.
>Implement a queue using arrays.
>Implement a circular queue using arrays.
>Write the functions in order, preorder and post order

NOTE: Total 3 questions will be given

First question is mandatory and it may come from III part

Second and third question may come from 1 part and second part respectively

Prepare well for viva. Expected viva question will be kept soon. In order, Preorder, Post order
functions, and insertion sort & quick sort programs simplified code will be kept soon

Further students are advised to bring Observation, Record and they have to come with decent
dress code

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

END THEORY EXAMINATIONS
Date Subject
26-05-08 Applied Physics
28-05-08 Electronic Devices & Circuits
30-05-08 C & Data Structures
02-06-08 Network Analysis
04-06-08 English
06-06-08 Mathematical Methods
09-06-08 Mathematics I

All the best for exams.

For Examination Tips Do visit www.mritsece.co.nr

The following is the second lab internal exam question paper
SET-A
1) Implement Bubble sort or exchange sort
2) Implement a program to count number of characters, number of words, numbers
of vowels and consonants, number of numbers, number of lines and also blank
spaces in a text using pointers.
3) Implement a program to accept records of different states using arrays of
structures. Display the state whose literacy rate is highest and whose income is
highest.
SET-B
4) Implement Selection sort.
5) Implement a program to illustrate the method of sending an entire structure as a
parameter to a function with the help of finding quadratic equation roots.

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

6) Find the length of the string using pointers.
SET-C
7) Implement Insertion sort
8) Addition and multiplication of two matrices.
9) To calculate subject wise and student wise total marks using structures.
SET-D
10) Implement Merge sort.
11) Implement a program that uses a structure to perform the operations reading a
complex number, writing a complex number, addition of two complex numbers and
multiplication of two complex numbers.
12) Print Pascal triangle up to 7 rows.
SET-E
13) Implement Binary search.
14) Implement a program to compute the monthly pay of 100 employees using
each employee’s name and basic pay. The DA is computed as 52% of the basic pay.
Gross-salary (Basic +DA). Print the employee’s name and Gross salary
15) Generate Fibonacci series using Recursion.
SET-F
16) Convert Infix expression to Postfix expression.
17) Compare the two structure variables.
18) Generating prime numbers up to 100.
SET-G
19) Implement linear search.
20) Implement a program to count number of characters, number of words,
numbers of vowels and consonants, number of numbers, number of lines and also
blank spaces in a file.
21) Test for upper triangular matrix.
SET-H
22) Evaluate Postfix expression.
23) Print the English alphabets A-Z and a-z using corresponding ASCII values.
24) File copy program using command line arguments.
SET-I
25) Implement a queue using arrays.
26) String comparison using pointers.

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

27) Implement a program to open an pre-existing file and add information at the
end of the file. Display the contents of the file before and after appending.
SET-J
28) Convert Infix expression to Postfix expression.
29) Implement a program to concatenate three names namely first name, second
name and third name into a single name to be called name.
30) Demonstrate Storage classes.
SET-K
31) Evaluate Postfix expression.
32) Write a c program to read the text after skipping n characters from the
beginning of the file.
33) Demonstrate Parameter passing mechanisms Call-by-value & Call-by-reference
SET-L
34) Implement a queue using arrays.
35) Sort the given names in alphabetical order.
36) Program to find sum of individual digits of a number also check for Palindrome
and Armstrong.

The following are the question numbers of important
programs from the lab manual:
8,9,11,12a,12d,13a,13b,16,17d,18,19,20,21
iii,22ii,23iii,25,26,27,28,29,30,31,34,36,37,38,39,40,
41,43,44,45,46,47,49,50,51,52,54,55,56,57,58,59,60,61

Also questions from previous question papers.

Programs from DS:
1.Conversion from Infix to Postfix.
2.Evaluation of Postfix.

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

3.Queue.
4.Circular Queue.

Infix to postfix using stacks

#include<stdio.h>

#include<conio.h>`

#include<process.h>

#include<string.h>

char stack[20];

int top=-1;

void postfixof(char infix[]);

void push(char);

char pop();

int main()

{

char infix[20];

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

clrscr();

puts("enter a infix expression");

gets(infix);

puts("\npostfix expression");

postfixof(infix);

getch();

return 0;

}

void push(char s)

{

if(top>=19)

{

puts("stack overflow");

exit(0);

}

else

{

stack[++top]=s;

}

}

char pop()
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

{

char num;

if(top==-1)

{

puts("stack is empty");

getch();

return 0;

}

else

{

num=stack[top--];

}

return num;

}

int test(char ch)

{

if(ch=='/') return 5;

else if(ch=='*') return 4;

else if(ch=='+') return 3;

else return 2;

}
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

void postfixof(char infix[])

{

int length;

static int i=0,j=0;

char s,t;

char postfix[40];

length=strlen(infix);

push('#');

while(i<length)

{

s=infix[i];

switch(s)

{

case '(': push(s); break;

case ')': t=pop();

while(t!='(')

{

postfix[j++]=t;

t=pop();

}

break;
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

case '+':

case '-':

case '*':

case '/':

case '^':

while(test(stack[top])>test(s))

{

t=pop();

postfix[j++]=t;

}

push(s); break;

default : postfix[j++]=s; break;

}

i++;

}

while(top>0)

{

t=pop();

postfix[j++]=t;

}

postfix[j++]='\0';
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

puts(postfix);

return;

}

Postfix evaluation

#include<stdio.h>

#include<conio.h>

#include<ctype.h>

#include<math.h>

float stack[10];

int top=-1;

void push(char);

float pop();

float postfixeval(char postfix[],float number[]);

int main()

{

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

int i=0;

char postfix[20];

float number[20],res;

clrscr();

printf("\n enter a postfix expression");

gets(postfix);

while(postfix[i]!='\0')

{

if(isalpha(postfix[i]))

{

fflush(stdin);

printf("\n enter number for %c",postfix[i]);

scanf("%f",&number[i]);

}

i++;

}

res=postfixeval(postfix,number);

printf("the res of %s=%f",postfix,res);

getch();

return 0;

}
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

float postfixeval(char postfix[],float number[])

{

int i=0;

float opa,opb,res;

char ch;

while(postfix[i]!='\0')

{

ch=postfix[i];

if(isalpha(postfix[i]))

{

push(number[i]);

}

else

{

opb=pop();

opa=pop();

switch(ch)

{

case '+': push(opa+opb); break;

case '-': push(opa+opb); break;
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

case '*': push(opa+opb); break;

case '/': push(opa+opb); break;

case '^': push(pow(opa,opb)); break;

}

}

i++;

}

res=pop();

return res;

}

void push(char c)

{

stack[++top]=c;

}

float pop()

{

float n;

n=stack[top--];

return n;

}

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

Queue operations

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int r=-1,f=-1,j,n,*queue,element,ch;

void display();

void insert();

int del();

int main()

{

clrscr();

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

printf("\n enter the size of the queue");

scanf("%d",&n);

queue=(int*)malloc(n*2);

while(1)

{

printf("\n enter ur choice\n 1.insert \n 2.display \n 3.delete \n 4.exit");

scanf("%d",&ch);

switch(ch)

{

case 1:insert();break;

case 2:

printf("\n Elements of queue are:");

display();

break;

case 3:element=del();

printf("the element deleted is %d",element);

break;

default: exit(0);

}

}

getch();
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

return 0;

}

void display()

{

for(r=0;r<n;r++)

printf("%d",queue[r]);

}

void insert()

{

while(1)

{

if(r>=n)

{

printf("overflow");

break;

}

else

{

printf("enter a no to insert");
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

scanf("%d",&element);

queue[++r]=element;

}

}

}

int del()

{

if(f==r)

{

printf("the queue is empty");

return 0;

}

f++;

element=queue[f];

if(f==n)

{

f=1;

r=1;

}

return element;

}
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

Circular queue operations

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int r=-1,f=-1,j,n,*queue,element,ch;

void display();

void insert();

int del();

int main()

{

clrscr();

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

printf("\n enter the size of the queue");

scanf("%d",&n);

queue=(int*)malloc(n*2);

while(1)

{

printf("\n enter ur choice\n 1.insert \n 2.display \n 3.delete \n 4.exit");

scanf("%d",&ch);

switch(ch)

{

case 1:insert();break;

case 2:

printf("\n Elements of queue are:");

display();

break;

case 3:element=del();

printf("the element deleted is %d",element);

break;

default: exit(0);

}

}

getch();
For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

return 0;

}

void display()

{

for(r=0;r<n;r++)

printf("%d",queue[r]);

}

void insert()

{

while(1)

{

if((r==n-1))

{

printf("overflow");

break;

}

printf("enter a no to insert");

scanf("%d",&element);

queue[++r]=element;

For academic links visit :
www.ademics.co.nr
Do visit www.mritsece.co.nr
www.mrits.co.nr

if(f==r)

f=0;

}

}

int del()

{

if(f==n)

f=0;

if(f==r)

{

printf("the queue is empty");

return 0;

}

f++;

element=queue[f];

return element;

}

For academic links visit :
www.ademics.co.nr