0% found this document useful (0 votes)
13 views7 pages

C Programs for Data Structures Practice

The document outlines a practice sheet for a Data Structures course (CSN 102) with programming exercises in C. It includes tasks such as reading an array, performing stack operations, copying arrays, counting duplicates, merging arrays, and finding unions and intersections. Each task provides hints or sample code to guide students in their implementations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views7 pages

C Programs for Data Structures Practice

The document outlines a practice sheet for a Data Structures course (CSN 102) with programming exercises in C. It includes tasks such as reading an array, performing stack operations, copying arrays, counting duplicates, merging arrays, and finding unions and intersections. Each task provides hints or sample code to guide students in their implementations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programs Practice Sheet 1: CSN 102: Data Structures

1. Write a program that reads an array of 100 integers.


Display all the pairs of elements whose sum is 6.

2. Write a C Program to print an array after it is rotated k


times.
Hint:
3. Write a C program to perform the stack operations using
an array.
#include <stdio.h>
int stack[100],i,j,choice=0,n,top=-1;
void push();
void pop();
void show();
void main ()
{

printf("Enter the number of elements in the stack ");


scanf("%d",&n);
printf("*********Stack operations using
array*********");
printf("\n------------------------------------------ \n");
while(choice != 4)
{
printf("Chose one from the below options...\n");
printf("\[Link]\[Link]\[Link]\[Link]");
printf("\n Enter your choice \n");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
show();
break;
}
case 4:
{
printf("Exiting.... ");
break;
}
default:
{
printf("Please Enter valid choice ");
}
};
}
}

void push ()
{
int val;
if (top == n )
printf("\n Overflow");
else
{
printf("Enter the value?");
scanf("%d",&val);
top = top +1;
stack[top] = val;
}
}

void pop ()
{
if(top == -1)
printf("Underflow");
else
top = top -1;
}
void show()
{
for (i=top;i>=0;i--)
{
printf("%d\n",stack[i]);
}
if(top == -1)
{
printf("Stack is empty");
}
}

4. Write a program in C to copy the elements of one array


into another array.
Test Data :
Input the number of elements to be stored in the array :3
Input 3 elements in the array :
element - 0 : 15
element - 1 : 10
element - 2 : 12
Expected Output :
The elements stored in the first array are :
15 10 12
The elements copied into the second array are :
15 10 12
Sol:
5. Write a program in C to count the total number of
duplicate elements in an array.
Test Data :
Input the number of elements to be stored in the array :3
Input 3 elements in the array :
element - 0 : 5
element - 1 : 1
element - 2 : 1
Expected Output :
Total number of duplicate elements found in the array is :
1

6. Write a C program to merge two arrays.


7. Write a C program to print the union and intersection of
the arrays.
8. Write a C program to reverse an array or swap first with
last element, second with second last…..

You might also like