You are on page 1of 11

PCA1 ASSIGNMENT

Course Code-PCC-CS(AIML)391

NAME- ADITI DAS


COLLEGE ID.-20273030175
DEPARTMENT- B.TECH AI & ML

1. #include<stdio.h>

int main()

int ar[20],pos,len,i,element;

printf("\n enter length of the array:");

scanf("%d",&len);

//Creating and printing array----------------

printf("\n Enter elements:");

for(i=0;i<len;i++)

scanf("\n %d",&ar[i]);

printf("ar[%d]=%d",i,ar[i]);

printf("\n enter the position to be inserted:");

scanf("%d",&pos);

printf("\n enter the element to be inserted:");

scanf("%d",&element);
//inserting element------------------

for(i=len;i>=pos;i--)

if(i!=pos)

ar[i]=ar[i-1];

else

ar[pos]=element;

//printing array after insertion--------------

for(i=0;i<=len;i++)

printf("\n %d",ar[i]);

OUTPUT:
enter length of the array:5

Enter elements:78
ar[0]=78
90
ar[1]=90
4576
ar[2]=4576
45
ar[3]=45
23
ar[4]=23
enter the position to be inserted:3

enter the element to be inserted:-90

78
90
4576
-90
45
23

2. #include<stdio.h>

int main()

int ar[10],n,pos,i;

printf("\n Enter the number of elements:");

scanf("%d",&n);

printf("\n Enter the position of the deleting element:");

scanf("%d",&pos);

printf("\n Enter the elments:");


/* -------entering and printing array elements------- */

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

scanf("%d",&ar[i]);

printf("\n ar[%d]=%d",i,ar[i]);

printf("\n");

/* ---------deleting array element------------ */

for(i=pos;i<n-1;i++)

ar[i]=ar[i+1];

n--;

/* -----------printing array after deletion of element----------*/

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

printf("\n ar[%d]=%d",i,ar[i]);

OUTPUT:
Enter the number of elements:5

Enter the position of the deleting element:2

Enter the elments:0

ar[0]=0
1

ar[1]=1
2

ar[2]=2
3

ar[3]=3
4

ar[4]=4

ar[0]=0
ar[1]=1
ar[2]=3
ar[3]=4

3. #include<stdio.h>

int main()

int ar[10],i,l;

printf("\n Enter the length of the array: ");

scanf("%d",&l);
//creating the array and printing it----------------

printf("\n Enter the elements of the array:");

for (i=0;i<l;i++)

scanf("\n %d",&ar[i]);

printf("\n ar[%d]=%d",i,ar[i]);

//reversing the array------------------

for(i=l-1;i>=0;i--)

printf("\n ar[%d]=%d",i,ar[i]);

return 0;

OUTPUT:
Enter the length of the array: 5

Enter the elements of the array:0

ar[0]=0
1

ar[1]=1
2
ar[2]=2
3

ar[3]=3
4

ar[4]=4

ar[4]=4
ar[3]=3
ar[2]=2
ar[1]=1
ar[0]=0

4. #include<stdio.h>

int size=10;

int stack[20];

int top=-1;

int isEmpty()

if(top==-1)

return 1;

else

{
return 0;

int isFull()

if(top==size-1)

return 1;

else

return 0;

int pop()

int element;

if(isEmpty())

printf("\n Stack underflow");

else

element=stack[top];

top--;

return element;
}

int push(int item)

if(isFull())

printf("\n stack overflow");

else

top++;

stack[top]=item;

int main()

int i,dlt;

push(10);

push(20);

push(30);

push(40);

push(50);

push(60);

push(70);
push(80);

push(90);

push(100);

printf("\n Stack elements before pop operation:");

for(i=top;i>=0;i--)

printf("\n %d",stack[i]);

dlt=pop();

printf("\n The deleted item of the Stack=%d",dlt);

printf("\n Stack after pop operation:");

for(i=top;i>=0;i--)

printf("\n %d",stack[i]);

return 0;

OUTPUT:
Stack elements before pop operation:
100
90
80
70
60
50
40
30
20
10
The deleted item of the Stack=100
Stack after pop operation:
90
80
70
60
50
40
30
20
10
-----------------X----------------

You might also like