Category Archives: lab programs

VTU 3rd sem CSE/IS lab programs!!!!


Today i am posting DS/OOPS lab programs for 3rd sem ISE\CSE students as per VTU syllabus.I am uploading the ‘.c/.cpp’ file.You can download that to your pc and open with any text editor.These programs are erorr free and will definatenly ececute.The list of the programs will be updated by the time.

Prog 4: Design,develop,and execute a program in C to simulate the working of a Queue of integers using array.Provide the following operations:
a.Insert                           b.Delete                c.Display

#include<stdio.h>
#include<stdlib.h>
#define queue_size 5
int item,q[20],r,f,ch;
void insert()
{
if(r==queue_size-1)
{
printf(“full queue\n”);
return;
}
r=r+1;
q[r]=item;
}
void del()
{
if(f>r)
{
printf(“Queue Overflow\n”);
return;
}
printf(“Enter the element to be deleted %d:”,q[f++]);
if(f>r)
{
f=0;
r=-1;
}
}
void display()
{
int i;
printf(“The queue is:\n”);
for(i=f;i<=r;i++)
{
printf(“%d\n”,q[i]);
}
}
int main()
{
r=-1;
f=0;
for(;;)
{
printf(“\n1.Insert\n 2.Delete\n 3.Display\n 4.Exit\n”);
printf(“Enter your choice:\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:printf(“Enter the elements\n”);
scanf(“%d”,&item);
insert();
break;
case 2:del();
break;
case 3:printf(“———Display the Queue———\n”);
display();
break;
default:exit(0);
break;
}
}
return 1;

}

Download Queue program.c

Prog 2: Dsign,develop,and execute a prog in C to convert a given valid parethesized infix arithematic expression to postfix expression and then to print boyhe the expressions.The expression consists of single character operands and the binary operators+(plus),-(minus),*(multiply) and /(divide).


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
double compute(char symbol,double op1,double op2)
{
switch(symbol)
{
case’+’:return op1+op2;
case’-‘:return op1-op2;
case’*’:return op1*op2;
case’/’:return op1*op2;
case’$’:
case’^’:return pow(op1,op2);
}
}
int main()
{
double s[20],res,op1,op2;
int i,top;
char symbol,postfix[20];
printf(“\n Enter postfix expression\n”);
scanf(“%s”,postfix);
top=-1;
for(i=0;i<strlen(postfix);i++)
{
symbol=postfix[i];
if(isdigit(symbol))
s[++top]=symbol-‘0’;
else
{
op2=s[top–];
op1=s[top–];
res=compute(symbol,op1,op2);
s[++top]=res;
}
}
res=s[top–];
printf(“\n Result %f\n”,res);
}


Prog 3: Design,develop, and execute a prog in C  to evaluate a valid postfix expression using stack.Assume that the postfix expression is read as a single line consisting of non-negative single digit operands and binary arithematic operators.The arithematic operators are +(add),-(substract),*(multiply),/(divide).


#include<stdio.h>
#include<string.h>
int f(char symbol)
{
switch(symbol)
{
case’+’:
case’-‘:return 2;
case’*’:
case’/’:return 4;
case’^’:
case’$’:return 5;
case'(‘:return 0;
case’#’:return-1;
default:return 8;
}
}
int g(char symbol)
{
switch(symbol)
{
case’+’:
case’-‘:return 1;
case’*’:
case’/’:return 3;
case’$’:return 6;
case'(‘:return 9;
case’)’:return 0;
default:return 7;
}
}
int infix_postfix(char infix[],char postfix[])
{
int top,i,j;
char s[20],symbol;
top=-1;
s[++top]=’#’;
j=0;
for(i=0;i<strlen(infix);i++)
{
symbol=infix[i];
while(f(s[top])>g(symbol))
{
postfix[j]=s[top–];
j++;
}
if(f(s[top])!=g(symbol))
s[++top]=symbol;
else
top–;
}
while(s[top]!=’#’)
{
postfix[j++]=s[top–];
}
postfix[j]=”;
}
int main()
{
char infix[20],postfix[20];
printf(“\n Enter infix expression\n”);
scanf(“%s”,infix);
infix_postfix(infix,postfix);
printf(“\n The postfix:-\n”);
printf(“\n%s\n”,postfix);
return 0;
}

Download infix to postfix conversion prog.c

If the above download links are not working,please inform me,or comment in the post.I will update it as soon as possible.

via Blogger http://wetechgeeks.blogspot.com/2013/09/vtu-3rd-sem-cseis-lab-programs.html