0% found this document useful (0 votes)
7 views15 pages

Janvi DSA File

The document contains multiple programming assignments related to Object Oriented Programming submitted by a student at Panipat Institute of Engineering & Technology. It includes implementations of various algorithms such as Linear Search, Binary Search, Bubble Sort, Selection Sort, Insertion Sort, and Stack operations using C programming. Each program is accompanied by input prompts and expected outputs.

Uploaded by

ritika.cse-cs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

Janvi DSA File

The document contains multiple programming assignments related to Object Oriented Programming submitted by a student at Panipat Institute of Engineering & Technology. It includes implementations of various algorithms such as Linear Search, Binary Search, Bubble Sort, Selection Sort, Insertion Sort, and Stack operations using C programming. Each program is accompanied by input prompts and expected outputs.

Uploaded by

ritika.cse-cs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Panipat Institute of Engineering & Technology

Samalkha, Panipat
Department of Computer Science & Engineering

OBJECT ORIENTED PROGRAMMING


Code : -PC-CS-207AL

Submitted to:
Dr. Upasana Lakhina Submitted by:
Assistant professor Name: Janvi Rajpal
(CSE Department) Roll No.-2823177
Sec-B2, 3rd Semester

Kurukshetra University Kurukshetra,


India
PROGRAM – 1
LINEAR SEARCH

#include<stdio.h>
int main(){
int arr[10],i,b,found=0; for(i=0;i<10;i+
+)
{
printf("\n enter elements:");
scanf("%d",&arr[i]);
}
printf("\n original array");
for(i=0;i<10;i++)
{
printf("\n%d",arr[i]);
}
printf("\n enter element to search:");
scanf("%d",&b);
for(i=0;i<10;i++)
{
if(arr[i]==b)
{
printf("\n element founded at position %d\n",i+1);
found=1;
break;
}}
if(!found)
{ printf("not founded");
}
return 0;
}
OUTPUT –
PROGRAM – 2
BINARY SEARCH

#include<stdio.h>
int main(){
int arr[10],i,j,flag,pos,mid,b;
for(i=0;i<10;i++)
{
printf("\n enter elements:");
scanf("%d",&arr[i]);
}
printf("\n original array");
for(i=0;i<10;i++)
{
printf("\n%d",arr[i]);
}
printf("\n enter element to search:");
scanf("%d",&b);
i=0;
j=9;
flag=0; while(i<=j)
{ mid=(i+j)/2;
if(arr[mid]==b)
{
flag=1,pos=mid+1;
break;
}
if(arr[mid]>b)
j=mid-1;
if(arr[mid]<b)
i=mid+1;
}
if(flag==1)
{
printf("\nelement founded at position %d",pos);
}
else
{
printf("\n not founded");}
return 0;
}
OUTPUT –
PROGRAM – 3
BUBBLE SORT
#include<stdio.h>
int main(){
int arr[10],i,j,temp;
for(i=0;i<10;i++)
{
printf("\n enter elements:");
scanf("%d",&arr[i]);
}
printf("\n original array");
for(i=0;i<10;i++)
{
printf("\n%d",arr[i]);
}
for(i=0;i<9;i++)
{
for(j=0;j<9-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("\n sorted array:");
for(i=0;i<10;i++)
{
printf("\n%d",arr[i]);
}
return 0;
}
OUTPUT -
PROGRAM – 4
SELECTION SORT

#include<stdio.h>
int main()
{
int arr[10],i,j,temp;
for (i=0;i<10;i++)
{
printf("\n enter elements of array-");
scanf("%d",&arr[i]);
}
printf("\n Original array-");
for (i=0;i<10;i++)
{
printf("\n %d",arr[i]);
}
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for (i=0;i<10;i++)
printf("\n sorted array is-%d",arr[i]);
return 0;
}
OUTPUT –
PROGRAM – 5
INSERTION SORT

#include<stdio.h>
int main()
{
int arr[10],i,j,key;
for (i=0;i<10;i++)
{
printf("\n enter elements of array-");
scanf("%d",&arr[i]);
}
printf("\n Original array-");
for (i=0;i<10;i++)
{
printf("\n %d",arr[i]);
}
for(i=1;i<10;i++)
{
key=arr[i];
j=i-1;
while(key<arr[j]&&j>=0)
{
arr[j+1]=arr[j];
j--;
}
arr[j+1]=key;
}
printf("\n sorted array-");
for (i=0;i<10;i++)

printf("\n %d",arr[i]);
return 0;
}
OUTPUT –
PROGRAM – 6
PUSH AND
POP

#include <stdio.h>
#define MAX 10

int main() {
int stack[MAX];
int top = -1;
int choice, value;

do {
printf("\nStack Operations:\n");
printf("1. Push\n");
printf("2. Pop\n");
printf("3. Display\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
if (top == MAX - 1) {
printf("Stack Overflow! %d\n", value);
} else {
printf("Enter value to push: ");
scanf("%d", &value);
top++;
stack[top] = value;
printf("Pushed %d to stack.\n", value);
}
break;
case 2:
if (top == -1) {
printf("Stack Underflow!\n");
} else {
printf("Popped %d from stack.\n", stack[top]);
top--;
}
break;

case 3:
if (top == -1) {
printf("Stack is empty.\n");
} else {
printf("Stack elements: ");
for (int i = top; i >= 0; i--) {
printf("%d ", stack[i]);
}
printf("\n");
}
break;

case 4:
printf("Exiting...\n");
break;

default:
printf("Invalid choice! Please enter a valid option.\n");
}
} while (choice != 4);

return 0;
}
OUTPUT –

You might also like