Lab Report: Course Title Course Code
Lab Report: Course Title Course Code
Lab Report
Course Title: Data Structure Lab
Course Code: CSE 106
Date of submission: 15/10/20
Remarks
1. Create an array of 10 size and assign 10 random
numbers. Now find the sum of the array using for and
while loop.
#include<stdio.h>
int main()
{
int i, Size, a[10];
int j = 0, Addition = 0;
printf("Please Enter the Size of an Array: ");
scanf("%d", &Size);
printf("\nPlease Enter Array Elements\n");
for(i = 0; i < Size; i++)
{
scanf("%d", &a[i]);
}
while(j < Size )
{
Addition = Addition + a[j];
j++;
}
printf("Sum of All Elements in an Array = %d ", Addition);
return 0;
}
2. For the following Stack operations print the popped
element for each time: The maximum size of the stack is:
3 Push(10), Push(20), Pop(), Pop(), Pop(),Push(50), Pop
#include<stdio.h>p
int arr[3];
int N=3;
int top=-1;
void push(int data)
{
if (top==N-1)
printf("overflow....\n");
else
{
top=top+1;
arr[top]=data;
}
}
void pop()
{
if (top==-1)
printf("underflow...\n");
else
{
printf("%d\n",arr[top]);
top=top-1;
}
}
int main()
{
push(10);
push(20);
pop();
pop();
pop();
push(50);
pop();
}