Adil Dsa
Adil Dsa
Adil Dsa
Name-Adil Inamdar
USN-2KE21MCA47-T
18/03/22*/
#include <stdio.h>
int gcd(int a, int b);
int main() {
int a, b;
printf("program executed by Adil\n");
printf("Enter two positive integers:\n");
scanf("%d %d", &a, &b);
printf("G.C.D of %d and %d is %d.", a, b, gcd(a, b));
return 0;
}
int main()
{
int num;
int result;
printf("program executed by Adil\n");
printf("Enter the nth number in fibonacci series: ");
scanf("%d", &num);
if (num < 0)
{
printf("Fibonacci of negative number is not possible.\n");
}
else
{
result = fib(num);
printf("The %d number in fibonacci series is %d\n", num, result);
}
return 0;
}
int fib(int num)
{
if (num == 0)
{
return 0;
}
else if (num == 1)
{
return 1;
}
else
{
return(fib(num - 1) + fib(num - 2));
}
}
int main()
{
int num;
printf("program executed by Adil\n");
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
towers(num, 'A', 'C', 'B');
return 0;
}
void towers(int num, char src, char dst, char aux)
{
if (num == 1)
{
printf("\n Move disk 1 from %c to %c",src, dst);
return;
}
towers(num - 1,src, aux, dst);
printf("\n Move disk %d from %c to %c", num, src, dst);
towers(num - 1, aux, src, dst);
}
};
typedef struct stack *s1;
void push(s1 p, int x);
int pop(s1 p);
int empty(s1 p);
int full(s1 p);
void main()
{
struct stack s;
int i,elem,ch,done=1;
int temp;
s.temp=-1;
while (done)
{
printf("\nProgram executed by Adil\n");
printf(" 1.insert\n 2.Delete\n 3.Display\n 4.EXIT\n");
printf("Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter Element\n");
scanf("%d",&elem);
push(&s,elem);
break;
case 2: temp=pop(&s);
printf("item deleted is %d",temp);
break;
}
}
if(full(p))
{
printf("ERROR OVERFLOW\n");
return ;
}
++(p->temp);
p->items[p->temp]=x;
}
int full(s1 p)
{
if(p->temp==MAX-1)
return 1;
else
return 0;
}
#include<conio.h>
char stack[100];
int top = -1;
void push(char x) {
stack[++top] = x;
}
char pop() {
if (top == -1)
return -1;
else
return stack[top--];
}
int priority(char x) {
if (x == '(')
return 0;
if (x == '+' || x == '-')
return 1;
if (x == '*' || x == '/')
return 2;
if (x == '^')
return 3;
return 0;
}
int main() {
printf("Executed by Adil\n");
char exp[100];
char * e, x;
printf("enter the expression::");
scanf("%s", exp);
printf("\n");
} else {
while (priority(stack[top]) >= priority( * e))
printf("%c", pop());
push( * e);
}
e++;
}
while (top != -1) {
printf("%c", pop());
}
return (0);
ab+c-
Executed by Adil
enter the expression::a+b-c/d
ab+cd/-
}
push(n3);
}
e++;
int main()
{
printf("Prgram Executed by Adil\n");
printf("INPUT THE INFIX EXPRESSION : ");
scanf("%s",infix);
infix_to_prefix();
return 0;
}
void push(int pos)
{
if(top == MAX-1)
{
printf("\nSTACK OVERFLOW\n");
}
else {
top++;
stack[top] = infix[pos];
}}
char pop()
{
char ch;
if(top < 0)
{
printf("\nSTACK UNDERFLOW\n");
void display()
int choice,item;
while(1)
{
printf("Program is Executed by Adil\n");
printf("Queue implementation\n");
printf("1.insert\t2.Delete\t3.dislpay\t4.exit\n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("Enter the element to be inserted:\n");
scanf("%d",&item);
insert(item);
break;
case 2:delete();
break;
case 3:printf("the contents of the queue are:\n");
display();
break;
case 4:exit(0);
default:printf("invalid choice\n");
break;
}
}
}
#define max 2
int CQ[max];
int front=0,rear=-1,count=0;
}
void main()
{
printf("Program Executed by Adil\n\n");
int choice,item;
while(1)
{
printf("1.Insert\n2.Delete\n3.Dislpay\n4.Exit\n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("Enter the element to be inserted:\n");
scanf("%d",&item);
insert(item);
break;
case 2:delete();
break;
case 3:
display();
break;
case 4: exit(0);
default:printf("invalid choice");
break;
}}
}
1.Insert
2.Delete
3.Dislpay
4.Exit
Enter your choice
1
Enter the element to be inserted:
11
Element 11 Inserted
1.Insert
2.Delete
3.Dislpay
4.Exit
Enter your choice
1
Enter the element to be inserted:
22
Element 22 Inserted
1.Insert
2.Delete
3.Dislpay
4.Exit
Enter your choice
1
Enter the element to be inserted:
33
Element 33 Inserted
1.Insert
2.Delete
3.Dislpay
4.Exit
Enter your choice
1
Enter the element to be inserted:
44
Element 44 Inserted
1.Insert
2.Delete
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:1
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:3
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:6
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:4
Element deleted is 33
Program executed by Adil
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:5
Element deleted is 44
Program executed by Adil
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:4
Element deleted is 22
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:5
Element deleted is 11
Program executed by Adil
1.Create
2.Insert(rear)
3.Insert(front)
4.Delete(rear)
5.Delete(front)
6.Display
7.Exit
Enter your choice:4
Queue is empty!!
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
1
Enter the number
44
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
1
Enter the number
11
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
1
Enter the number
33
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
1
Enter the number
77
1.Insert
2.Delete
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
1
Enter the number
55
Queue is full!!
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
3
Elements of queue are
11
22
33
44
77
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
2
The deleted element is 11
1.Insert
2.Delete
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
2
The deleted element is 33
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
2
The deleted element is 44
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
2
The deleted element is 77
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice
2
Queue is empty!!
Empty queue
1.Insert
void main ()
{
int choice=0;
printf("\nProgram executed Adil\n");
printf("----------------------------------------------");
while(choice != 4)
{
printf("\nChose one from the below options...");
printf("\n1.Push\n2.Pop\n3.Show\n4.Exit");
printf("\nEnter your choice \n");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
1
Enter value
5
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
1
Enter value
10
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
1
Enter value
20
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
1
Enter value
30
1.insert an element
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
3
printing values....
5
10
20
30
40
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
2
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
2
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
2
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
2
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
2
UNDERFLOW
1.insert an element
2.Delete an element
3.Display the queue
4.Exit
Enter your choice
4
--------------------------------
}
}
void merge(int a[],int i1,int i2,int j1,int j2)
{
int temp[50];
int i,j,k;
i=i1;
j=j1;
k=0;
for(j=1;j<=n;j++){
scanf ("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=INFINITY;
}
}
}
}
}
while(i<j);
a[l]=a[j];
a[j]=p;
return j;
}
int find(int i)
{
while(parent[i])
i=parent[i];
return i;
}
Minimum cost=20
void main()
{
printf("Program Executed by Adil\n\n");
int i,j,count=0;
printf("Enter the number of vertices\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
reach[i]=0;
a[i][j]=0;
}
printf("Enter adjacency matrix\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
dfs(1);
for(i=1;i<=n;i++)
if(reach[i])
count++;
if(count==n)
printf("\nGraph is connected\n");
else
printf("Graph is not connected");
void dfs(int v)
{
int i;
reach[v]=1;
}
}