ADA FILE

Gaurav Singh
Gaurav SinghLecturer en S.R.G.O.C , Shri Ram Group of Colleges

ADA PRACTICAL FILE

1.Program for search an element by using linearsearch
algorithm.
#include <stdio.h>
#include<conio.h>
int main()
{
int array[100], search, c, n;
printf("Enter the number of elements in arrayn");
scanf("%d",&n);
printf("Enter %d integer(s)n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter the number to searchn");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* if required element found */
{
printf("%d is present at location %d.n", search, c+1);
break;
}
}
if (c == n)
printf("%d is not present in array.n", search);
getch();
}
OUTPUT-
2.Program for search an element by using binary search
algorithm.
#include <stdio.h>
#include<conio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
printf("Enter number of elementsn");
scanf("%d",&n);
printf("Enter %d integersn", n);
for (c = 0; c < n; c++)
scanf("%d",&array[c]);
printf("Enter value to findn");
scanf("%d", &search);
first = 0;
last = n - 1;
middle = (first+last)/2;
while (first <= last) {
if (array[middle] < search)
first = middle + 1;
else if (array[middle] == search) {
printf("%d found at location %d.n", search, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d is not present in the list.n", search);
getch();
}
OUTPUT-
3.Program of sorting elements by using merge sort algorithm.
#include <stdio.h>
#include <conio.h>
int main( )
{
int a[5] = { 11, 2, 9, 13, 57 } ;
int b[5] = { 25, 17, 1, 90, 3 } ;
int c[10] ;
int i, j, k, temp ;
printf ( "Merge sort.n" ) ;
printf ( "nFirst array:n" ) ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%dt", a[i] ) ;
printf ( "nnSecond array:n" ) ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%dt", b[i] ) ;
for ( i = 0 ; i <= 3 ; i++ )
{
for ( j = i + 1 ; j <= 4 ; j++ )
{
if ( a[i] > a[j] )
{
temp = a[i] ;
a[i] = a[j] ;
a[j] = temp ;
}
if ( b[i] > b[j] )
{
temp = b[i] ;
b[i] = b[j] ;
b[j] = temp ;
}
}
}
for ( i = j = k = 0 ; i <= 9 ; )
{
if ( a[j] <= b[k] )
c[i++] = a[j++] ;
else
c[i++] = b[k++] ;
if ( j == 5 || k == 5 )
break ;
}
for ( ; j <= 4 ; )
c[i++] = a[j++] ;
for ( ; k <= 4 ; )
c[i++] = b[k++] ;
printf ( "nnArray after sorting:n") ;
for ( i = 0 ; i <= 9 ; i++ )
printf ( "%dt", c[i] ) ;
getch( ) ;
}
OUTPUT-
4.Program of sorting elements by using quick sort algorithm.
#include<stdio.h>
#include<conio.h>
void quicksort(int [10],int,int);
int main(){
int x[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter %d elements: ",size);
for(i=0;i<size;i++)
scanf("%d",&x[i]);
quicksort(x,0,size-1);
printf("Sorted elements: ");
for(i=0;i<size;i++)
printf(" %d",x[i]);
return 0;
}
void quicksort(int x[10],int first,int last){
int pivot,j,temp,i;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(x[i]<=x[pivot]&&i<last)
i++;
while(x[j]>x[pivot])
j--;
if(i<j){
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
quicksort(x,first,j-1);
quicksort(x,j+1,last);
}
getch();
}
OUTPUT-
5.Program of sorting elements by using selection sort
algorithm.
#include <stdio.h>
#include<conio.h>
int main()
{
int array[100], n, c, d, position, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);
for ( c = 0 ; c < ( n - 1 ) ; c++ )
{
position = c;
for ( d = c + 1 ; d < n ; d++ )
{
if ( array[position] > array[d] )
position = d;
}
if ( position != c )
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}
printf("Sorted list in ascending order:n");
for ( c = 0 ; c < n ; c++ )
printf("%dn", array[c]);
getch();
}
OUTPUT-
6.Program of sorting elements by using bubble sort algorithm.
#include<stdio.h>
#include<conio.h>
int main()
{
int s,temp,i,j,a[20];
printf("Enter total numbers of elements: ");
scanf("%d",&s);
printf("Enter %d elements: ",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
//Bubble sorting algorithm
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
getch();
}
OUTPUT-
7.Stack implementationusing array.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5
struct stack {
int s[size];
int top;
} st;
int stfull() {
if (st.top >= size - 1)
return 1;
else
return 0;
}
void push(int item) {
st.top++;
st.s[st.top] = item;
}
int stempty() {
if (st.top == -1)
return 1;
else
return 0;
}
int pop() {
int item;
item = st.s[st.top];
st.top--;
return (item);
}
void display() {
int i;
if (stempty())
printf("nStack Is Empty!");
else {
for (i = st.top; i >= 0; i--)
printf("n%d", st.s[i]);
}
}
int main() {
int item, choice;
char ans;
st.top = -1;
printf("ntImplementation Of Stack");
do {
printf("nMain Menu");
printf("n1.Push n2.Pop n3.Display n4.exit");
printf("nEnter Your Choice");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("nEnter The item to be pushed");
scanf("%d", &item);
if (stfull())
printf("nStack is Full!");
else
push(item);
break;
case 2:
if (stempty())
printf("nEmpty stack!Underflow !!");
else {
item = pop();
printf("nThe popped element is %d", item);
}
break;
case 3:
display();
break;
case 4:
exit(0);
}
printf("nDo You want To Continue?");
ans = getche();
} while (ans == 'Y' || ans == 'y');
getch();
}
OUTPUT-
8.Program to displayFibonacciseries using recursion.
#include<stdio.h>
#include<conio.h>
void printFibonacci(int);
int main(){
int k,n;
long int i=0,j=1,f;
printf("Enter the range of the Fibonacci series: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
printFibonacci(n);
return 0;
}
void printFibonacci(int n){
static long int first=0,second=1,sum;
if(n>0){
sum = first + second;
first = second;
second = sum;
printf("%ld ",sum);
printFibonacci(n-1);
}
getch();
}
OUTPUT-
9.Queue implementationusing array.
#include<stdio.h>
#include<conio.h>
#define MAX 10
void insert(int);
int del();
int queue[MAX], rear=0, front=0;
void display();
int main()
{
char ch , a='y';
int choice, token;
printf("1.Insert");
printf("n2.Delete");
printf("n3.show or display");
do
{
printf("nEnter your choice for the operation: ");
scanf("%d",&choice);
switch(choice)
{
case 1: insert(token);
display();
break;
token=del();
printf("nThe token deleted is %d",token);
display();
break;
case 3:
display();
break;
default:
printf("Wrong choice");
break;
}
printf("nDo you want to continue(y/n):");
ch=getch();
}
while(ch=='y'||ch=='Y');
getch();
}
void display()
{
int i;
printf("nThe queue elements are:");
for(i=rear;i<front;i++)
{
printf("%d ",queue[i]);
}
}
void insert(int token)
{
char a;
if(rear==MAX)
{
printf("nQueue full");
return;
}
do
{
printf("nEnter the token to be inserted:");
scanf("%d",&token);
queue[front]=token;
front=front+1;
printf("do you want to continue insertion Y/N");
a=getch();
}
while(a=='y');
}
int del()
{
int t;
if(front==rear)
{
printf("nQueue empty");
return 0;
}
rear=rear+1;
t=queue[rear-1];
return t;
}
OUTPUT-
10.Program for insertion, deletion,displayand traversal in
binary search tree.
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
void insert(int,int );
void delte(int);
void display(int);
int search(int);
int search1(int,int);
int tree[40],t=1,s,x,i;
main()
{
int ch,y;
for(i=1;i<40;i++)
tree[i]=-1;
while(1)
{
cout <<"1.INSERTn2.DELETEn3.DISPLAYn4.SEARCHn5.EXITnEnter your choice:";
cin >> ch;
switch(ch)
{
case 1:
cout <<"enter the element to insert";
cin >> ch;
insert(1,ch);
break;
case 2:
cout <<"enter the element to delete";
cin >>x;
y=search(1);
if(y!=-1) delte(y);
else cout<<"no such element in tree";
break;
case 3:
display(1);
cout<<"n";
for(int i=0;i<=32;i++)
cout <<i;
cout <<"n";
break;
case 4:
cout <<"enter the element to search:";
cin >> x;
y=search(1);
if(y == -1) cout <<"no such element in tree";
else cout <<x << "is in" <<y <<"position";
break;
case 5:
exit(0);
}
}
}
void insert(int s,int ch )
{
int x;
if(t==1)
{
tree[t++]=ch;
return;
}
x=search1(s,ch);
if(tree[x]>ch)
tree[2*x]=ch;
else
tree[2*x+1]=ch;
t++;
}
void delte(int x)
{
if( tree[2*x]==-1 && tree[2*x+1]==-1)
tree[x]=-1;
else if(tree[2*x]==-1)
{ tree[x]=tree[2*x+1];
tree[2*x+1]=-1;
}
else if(tree[2*x+1]==-1)
{ tree[x]=tree[2*x];
tree[2*x]=-1;
}
else
{
tree[x]=tree[2*x];
delte(2*x);
}
t--;
}
int search(int s)
{
if(t==1)
{
cout <<"no element in tree";
return -1;
}
if(tree[s]==-1)
return tree[s];
if(tree[s]>x)
search(2*s);
else if(tree[s]<x)
search(2*s+1);
else
return s;
}
void display(int s)
{
if(t==1)
{cout <<"no element in tree:";
return;}
for(int i=1;i<40;i++)
if(tree[i]==-1)
cout <<" ";
else cout <<tree[i];
return ;
}
int search1(int s,int ch)
{
if(t==1)
{
cout <<"no element in tree";
return -1;
}
if(tree[s]==-1)
return s/2;
if(tree[s] > ch)
search1(2*s,ch);
else search1(2*s+1,ch);
}
OUTPUT-

Recomendados

DAA Lab File C Programs por
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp Tiwari
25.3K vistas30 diapositivas
DataStructures notes por
DataStructures notesDataStructures notes
DataStructures notesLakshmi Sarvani Videla
353 vistas20 diapositivas
Cpds lab por
Cpds labCpds lab
Cpds labpraveennallavelly08
342 vistas23 diapositivas
design and analysis of algorithm Lab files por
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
789 vistas28 diapositivas
Data Structures Using C Practical File por
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
6.2K vistas82 diapositivas
c-programming-using-pointers por
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointersSushil Mishra
9K vistas48 diapositivas

Más contenido relacionado

La actualidad más candente

C lab manaual por
C lab manaualC lab manaual
C lab manaualmanoj11manu
1.9K vistas36 diapositivas
Daa practicals por
Daa practicalsDaa practicals
Daa practicalsRekha Yadav
2.3K vistas26 diapositivas
C programming array & shorting por
C  programming array & shortingC  programming array & shorting
C programming array & shortingargusacademy
1.2K vistas26 diapositivas
Solutionsfor co2 C Programs for data structures por
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
160 vistas13 diapositivas
C Prog - Array por
C Prog - ArrayC Prog - Array
C Prog - Arrayvinay arora
1.2K vistas39 diapositivas
C Programming Exam problems & Solution by sazzad hossain por
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainSazzad Hossain, ITP, MBA, CSCA™
1.6K vistas32 diapositivas

La actualidad más candente(20)

C lab manaual por manoj11manu
C lab manaualC lab manaual
C lab manaual
manoj11manu1.9K vistas
Daa practicals por Rekha Yadav
Daa practicalsDaa practicals
Daa practicals
Rekha Yadav2.3K vistas
C programming array & shorting por argusacademy
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy1.2K vistas
C Prog - Array por vinay arora
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora1.2K vistas
C Prog. - Strings (Updated) por vinay arora
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora1.1K vistas
Data structure output 1 por Balaji Thala
Data structure output 1Data structure output 1
Data structure output 1
Balaji Thala442 vistas
Basic c programs updated on 31.8.2020 por vrgokila
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila147 vistas
All important c programby makhan kumbhkar por sandeep kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar1K vistas
Data Structures Practical File por Harjinder Singh
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh12.3K vistas
Os lab file c programs por Kandarp Tiwari
Os lab file c programsOs lab file c programs
Os lab file c programs
Kandarp Tiwari14.9K vistas
SaraPIC por Sara Sahu
SaraPICSaraPIC
SaraPIC
Sara Sahu549 vistas
Datastructures asignment por sreekanth3dce
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce899 vistas
Double linked list por raviahuja11
Double linked listDouble linked list
Double linked list
raviahuja112.3K vistas

Destacado

Showcase por
ShowcaseShowcase
ShowcaseAmy Spradling
94 vistas27 diapositivas
Questionnaire research por
Questionnaire researchQuestionnaire research
Questionnaire researchJamesMarshallCHS
119 vistas7 diapositivas
information diet por
information dietinformation diet
information dietMesut Cura
178 vistas10 diapositivas
LibGuides 2 Team Meeting - April 22, 2015 por
LibGuides 2 Team Meeting - April 22, 2015LibGuides 2 Team Meeting - April 22, 2015
LibGuides 2 Team Meeting - April 22, 2015Elizabeth German
226 vistas23 diapositivas
Ümran sunum new 2 por
Ümran sunum new 2Ümran sunum new 2
Ümran sunum new 2enesummu
150 vistas49 diapositivas
La amistad...... por
La amistad......La amistad......
La amistad......Perlita Vargas
174 vistas7 diapositivas

Destacado(20)

information diet por Mesut Cura
information dietinformation diet
information diet
Mesut Cura178 vistas
LibGuides 2 Team Meeting - April 22, 2015 por Elizabeth German
LibGuides 2 Team Meeting - April 22, 2015LibGuides 2 Team Meeting - April 22, 2015
LibGuides 2 Team Meeting - April 22, 2015
Elizabeth German226 vistas
Ümran sunum new 2 por enesummu
Ümran sunum new 2Ümran sunum new 2
Ümran sunum new 2
enesummu150 vistas
George &amp; aina g por jordiidkyes
George &amp; aina gGeorge &amp; aina g
George &amp; aina g
jordiidkyes274 vistas
Programma completo palermo apre le porte por Viviana Monaco
Programma completo palermo apre le porteProgramma completo palermo apre le porte
Programma completo palermo apre le porte
Viviana Monaco1.5K vistas
Daniel R.P actual por Danno Piiio
Daniel R.P actualDaniel R.P actual
Daniel R.P actual
Danno Piiio344 vistas
Promoting the Role of Government in Child Well-Being por PublicWorks
Promoting the Role of Government in Child Well-BeingPromoting the Role of Government in Child Well-Being
Promoting the Role of Government in Child Well-Being
PublicWorks793 vistas

Similar a ADA FILE

Chapter 8 c solution por
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
9.1K vistas87 diapositivas
Ds por
DsDs
Dskooldeep12345
393 vistas4 diapositivas
Daapracticals 111105084852-phpapp02 por
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
124 vistas26 diapositivas
Cpd lecture im 207 por
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207Syed Tanveer
731 vistas21 diapositivas
C Programming Language Part 8 por
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
401 vistas18 diapositivas
Data Structure in C Programming Language por
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
1.3K vistas219 diapositivas

Similar a ADA FILE(20)

Chapter 8 c solution por Azhar Javed
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed9.1K vistas
Daapracticals 111105084852-phpapp02 por Er Ritu Aggarwal
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal124 vistas
C Programming Language Part 8 por Rumman Ansari
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
Rumman Ansari401 vistas
Data Structure in C Programming Language por Arkadeep Dey
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey1.3K vistas
Let us C (by yashvant Kanetkar) chapter 3 Solution por Hazrat Bilal
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal28.3K vistas
LET US C (5th EDITION) CHAPTER 2 ANSWERS por KavyaSharma65
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65583 vistas
C basics por MSc CST
C basicsC basics
C basics
MSc CST323 vistas
C Prog - Pointers por vinay arora
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora1.1K vistas
C tech questions por vijay00791
C tech questionsC tech questions
C tech questions
vijay007919.6K vistas

Más de Gaurav Singh

Oral presentation por
Oral presentationOral presentation
Oral presentationGaurav Singh
80.4K vistas18 diapositivas
srgoc dotnet_ppt por
srgoc dotnet_pptsrgoc dotnet_ppt
srgoc dotnet_pptGaurav Singh
710 vistas17 diapositivas
Srgoc dotnet_new por
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_newGaurav Singh
272 vistas23 diapositivas
Srgoc dotnet por
Srgoc dotnetSrgoc dotnet
Srgoc dotnetGaurav Singh
417 vistas18 diapositivas
srgoc por
srgocsrgoc
srgocGaurav Singh
279 vistas17 diapositivas
Srgoc linux por
Srgoc linuxSrgoc linux
Srgoc linuxGaurav Singh
236 vistas40 diapositivas

Más de Gaurav Singh(8)

Último

DESIGN OF SPRINGS-UNIT4.pptx por
DESIGN OF SPRINGS-UNIT4.pptxDESIGN OF SPRINGS-UNIT4.pptx
DESIGN OF SPRINGS-UNIT4.pptxgopinathcreddy
19 vistas47 diapositivas
Design of machine elements-UNIT 3.pptx por
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptxgopinathcreddy
34 vistas31 diapositivas
sam_software_eng_cv.pdf por
sam_software_eng_cv.pdfsam_software_eng_cv.pdf
sam_software_eng_cv.pdfsammyigbinovia
9 vistas5 diapositivas
START Newsletter 3 por
START Newsletter 3START Newsletter 3
START Newsletter 3Start Project
6 vistas25 diapositivas
REACTJS.pdf por
REACTJS.pdfREACTJS.pdf
REACTJS.pdfArthyR3
35 vistas16 diapositivas
MongoDB.pdf por
MongoDB.pdfMongoDB.pdf
MongoDB.pdfArthyR3
49 vistas6 diapositivas

Último(20)

Design of machine elements-UNIT 3.pptx por gopinathcreddy
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptx
gopinathcreddy34 vistas
REACTJS.pdf por ArthyR3
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
ArthyR335 vistas
MongoDB.pdf por ArthyR3
MongoDB.pdfMongoDB.pdf
MongoDB.pdf
ArthyR349 vistas
GDSC Mikroskil Members Onboarding 2023.pdf por gdscmikroskil
GDSC Mikroskil Members Onboarding 2023.pdfGDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdf
gdscmikroskil59 vistas
SPICE PARK DEC2023 (6,625 SPICE Models) por Tsuyoshi Horigome
SPICE PARK DEC2023 (6,625 SPICE Models) SPICE PARK DEC2023 (6,625 SPICE Models)
SPICE PARK DEC2023 (6,625 SPICE Models)
Tsuyoshi Horigome36 vistas
SUMIT SQL PROJECT SUPERSTORE 1.pptx por Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 22 vistas
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf por AlhamduKure
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdfASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
AlhamduKure6 vistas
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc... por csegroupvn
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
csegroupvn6 vistas
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth por Innomantra
BCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for GrowthBCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for Growth
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth
Innomantra 10 vistas
Proposal Presentation.pptx por keytonallamon
Proposal Presentation.pptxProposal Presentation.pptx
Proposal Presentation.pptx
keytonallamon63 vistas
Ansari: Practical experiences with an LLM-based Islamic Assistant por M Waleed Kadous
Ansari: Practical experiences with an LLM-based Islamic AssistantAnsari: Practical experiences with an LLM-based Islamic Assistant
Ansari: Practical experiences with an LLM-based Islamic Assistant
M Waleed Kadous7 vistas
Searching in Data Structure por raghavbirla63
Searching in Data StructureSearching in Data Structure
Searching in Data Structure
raghavbirla6314 vistas
fakenews_DBDA_Mar23.pptx por deepmitra8
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptx
deepmitra816 vistas

ADA FILE

  • 1. 1.Program for search an element by using linearsearch algorithm. #include <stdio.h> #include<conio.h> int main() { int array[100], search, c, n; printf("Enter the number of elements in arrayn"); scanf("%d",&n); printf("Enter %d integer(s)n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); printf("Enter the number to searchn"); scanf("%d", &search); for (c = 0; c < n; c++) { if (array[c] == search) /* if required element found */ { printf("%d is present at location %d.n", search, c+1); break; } } if (c == n) printf("%d is not present in array.n", search);
  • 3. 2.Program for search an element by using binary search algorithm. #include <stdio.h> #include<conio.h> int main() { int c, first, last, middle, n, search, array[100]; printf("Enter number of elementsn"); scanf("%d",&n); printf("Enter %d integersn", n); for (c = 0; c < n; c++) scanf("%d",&array[c]); printf("Enter value to findn"); scanf("%d", &search); first = 0; last = n - 1; middle = (first+last)/2; while (first <= last) { if (array[middle] < search) first = middle + 1; else if (array[middle] == search) { printf("%d found at location %d.n", search, middle+1); break; }
  • 4. else last = middle - 1; middle = (first + last)/2; } if (first > last) printf("Not found! %d is not present in the list.n", search); getch(); } OUTPUT-
  • 5. 3.Program of sorting elements by using merge sort algorithm. #include <stdio.h> #include <conio.h> int main( ) { int a[5] = { 11, 2, 9, 13, 57 } ; int b[5] = { 25, 17, 1, 90, 3 } ; int c[10] ; int i, j, k, temp ; printf ( "Merge sort.n" ) ; printf ( "nFirst array:n" ) ; for ( i = 0 ; i <= 4 ; i++ ) printf ( "%dt", a[i] ) ; printf ( "nnSecond array:n" ) ; for ( i = 0 ; i <= 4 ; i++ ) printf ( "%dt", b[i] ) ; for ( i = 0 ; i <= 3 ; i++ ) { for ( j = i + 1 ; j <= 4 ; j++ ) { if ( a[i] > a[j] ) { temp = a[i] ; a[i] = a[j] ;
  • 6. a[j] = temp ; } if ( b[i] > b[j] ) { temp = b[i] ; b[i] = b[j] ; b[j] = temp ; } } } for ( i = j = k = 0 ; i <= 9 ; ) { if ( a[j] <= b[k] ) c[i++] = a[j++] ; else c[i++] = b[k++] ; if ( j == 5 || k == 5 ) break ; } for ( ; j <= 4 ; ) c[i++] = a[j++] ; for ( ; k <= 4 ; ) c[i++] = b[k++] ; printf ( "nnArray after sorting:n") ;
  • 7. for ( i = 0 ; i <= 9 ; i++ ) printf ( "%dt", c[i] ) ; getch( ) ; } OUTPUT-
  • 8. 4.Program of sorting elements by using quick sort algorithm. #include<stdio.h> #include<conio.h> void quicksort(int [10],int,int); int main(){ int x[20],size,i; printf("Enter size of the array: "); scanf("%d",&size); printf("Enter %d elements: ",size); for(i=0;i<size;i++) scanf("%d",&x[i]); quicksort(x,0,size-1); printf("Sorted elements: "); for(i=0;i<size;i++) printf(" %d",x[i]); return 0; } void quicksort(int x[10],int first,int last){ int pivot,j,temp,i; if(first<last){ pivot=first; i=first; j=last; while(i<j){
  • 11. 5.Program of sorting elements by using selection sort algorithm. #include <stdio.h> #include<conio.h> int main() { int array[100], n, c, d, position, swap; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d integersn", n); for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); for ( c = 0 ; c < ( n - 1 ) ; c++ ) { position = c; for ( d = c + 1 ; d < n ; d++ ) { if ( array[position] > array[d] ) position = d; } if ( position != c ) { swap = array[c]; array[c] = array[position];
  • 12. array[position] = swap; } } printf("Sorted list in ascending order:n"); for ( c = 0 ; c < n ; c++ ) printf("%dn", array[c]); getch(); } OUTPUT-
  • 13. 6.Program of sorting elements by using bubble sort algorithm. #include<stdio.h> #include<conio.h> int main() { int s,temp,i,j,a[20]; printf("Enter total numbers of elements: "); scanf("%d",&s); printf("Enter %d elements: ",s); for(i=0;i<s;i++) scanf("%d",&a[i]); //Bubble sorting algorithm for(i=s-2;i>=0;i--){ for(j=0;j<=i;j++){ if(a[j]>a[j+1]){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } printf("After sorting: "); for(i=0;i<s;i++) printf(" %d",a[i]);
  • 15. 7.Stack implementationusing array. #include<stdio.h> #include<conio.h> #include<stdlib.h> #define size 5 struct stack { int s[size]; int top; } st; int stfull() { if (st.top >= size - 1) return 1; else return 0; } void push(int item) { st.top++; st.s[st.top] = item; } int stempty() { if (st.top == -1) return 1; else return 0;
  • 16. } int pop() { int item; item = st.s[st.top]; st.top--; return (item); } void display() { int i; if (stempty()) printf("nStack Is Empty!"); else { for (i = st.top; i >= 0; i--) printf("n%d", st.s[i]); } } int main() { int item, choice; char ans; st.top = -1; printf("ntImplementation Of Stack"); do { printf("nMain Menu"); printf("n1.Push n2.Pop n3.Display n4.exit");
  • 17. printf("nEnter Your Choice"); scanf("%d", &choice); switch (choice) { case 1: printf("nEnter The item to be pushed"); scanf("%d", &item); if (stfull()) printf("nStack is Full!"); else push(item); break; case 2: if (stempty()) printf("nEmpty stack!Underflow !!"); else { item = pop(); printf("nThe popped element is %d", item); } break; case 3: display(); break; case 4: exit(0);
  • 18. } printf("nDo You want To Continue?"); ans = getche(); } while (ans == 'Y' || ans == 'y'); getch(); } OUTPUT-
  • 19. 8.Program to displayFibonacciseries using recursion. #include<stdio.h> #include<conio.h> void printFibonacci(int); int main(){ int k,n; long int i=0,j=1,f; printf("Enter the range of the Fibonacci series: "); scanf("%d",&n); printf("Fibonacci Series: "); printf("%d %d ",0,1); printFibonacci(n); return 0; } void printFibonacci(int n){ static long int first=0,second=1,sum; if(n>0){ sum = first + second; first = second; second = sum; printf("%ld ",sum); printFibonacci(n-1); } getch();
  • 21. 9.Queue implementationusing array. #include<stdio.h> #include<conio.h> #define MAX 10 void insert(int); int del(); int queue[MAX], rear=0, front=0; void display(); int main() { char ch , a='y'; int choice, token; printf("1.Insert"); printf("n2.Delete"); printf("n3.show or display"); do { printf("nEnter your choice for the operation: "); scanf("%d",&choice); switch(choice) { case 1: insert(token); display(); break;
  • 22. token=del(); printf("nThe token deleted is %d",token); display(); break; case 3: display(); break; default: printf("Wrong choice"); break; } printf("nDo you want to continue(y/n):"); ch=getch(); } while(ch=='y'||ch=='Y'); getch(); } void display() { int i; printf("nThe queue elements are:"); for(i=rear;i<front;i++) { printf("%d ",queue[i]);
  • 23. } } void insert(int token) { char a; if(rear==MAX) { printf("nQueue full"); return; } do { printf("nEnter the token to be inserted:"); scanf("%d",&token); queue[front]=token; front=front+1; printf("do you want to continue insertion Y/N"); a=getch(); } while(a=='y'); } int del() { int t;
  • 25. 10.Program for insertion, deletion,displayand traversal in binary search tree. #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; void insert(int,int ); void delte(int); void display(int); int search(int); int search1(int,int); int tree[40],t=1,s,x,i; main() { int ch,y; for(i=1;i<40;i++) tree[i]=-1; while(1) { cout <<"1.INSERTn2.DELETEn3.DISPLAYn4.SEARCHn5.EXITnEnter your choice:"; cin >> ch; switch(ch) { case 1:
  • 26. cout <<"enter the element to insert"; cin >> ch; insert(1,ch); break; case 2: cout <<"enter the element to delete"; cin >>x; y=search(1); if(y!=-1) delte(y); else cout<<"no such element in tree"; break; case 3: display(1); cout<<"n"; for(int i=0;i<=32;i++) cout <<i; cout <<"n"; break; case 4: cout <<"enter the element to search:"; cin >> x; y=search(1); if(y == -1) cout <<"no such element in tree"; else cout <<x << "is in" <<y <<"position";
  • 27. break; case 5: exit(0); } } } void insert(int s,int ch ) { int x; if(t==1) { tree[t++]=ch; return; } x=search1(s,ch); if(tree[x]>ch) tree[2*x]=ch; else tree[2*x+1]=ch; t++; } void delte(int x) {
  • 28. if( tree[2*x]==-1 && tree[2*x+1]==-1) tree[x]=-1; else if(tree[2*x]==-1) { tree[x]=tree[2*x+1]; tree[2*x+1]=-1; } else if(tree[2*x+1]==-1) { tree[x]=tree[2*x]; tree[2*x]=-1; } else { tree[x]=tree[2*x]; delte(2*x); } t--; } int search(int s) { if(t==1) { cout <<"no element in tree"; return -1; }
  • 29. if(tree[s]==-1) return tree[s]; if(tree[s]>x) search(2*s); else if(tree[s]<x) search(2*s+1); else return s; } void display(int s) { if(t==1) {cout <<"no element in tree:"; return;} for(int i=1;i<40;i++) if(tree[i]==-1) cout <<" "; else cout <<tree[i]; return ; } int search1(int s,int ch) { if(t==1) {
  • 30. cout <<"no element in tree"; return -1; } if(tree[s]==-1) return s/2; if(tree[s] > ch) search1(2*s,ch); else search1(2*s+1,ch); } OUTPUT-