SlideShare ist ein Scribd-Unternehmen logo
1 von 30
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-

Weitere Àhnliche Inhalte

Was ist angesagt?

C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
SaraPIC
SaraPICSaraPIC
SaraPIC
Sara Sahu
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 

Was ist angesagt? (20)

C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
C programs
C programsC programs
C programs
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
C file
C fileC file
C file
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Double linked list
Double linked listDouble linked list
Double linked list
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
Ada file
Ada fileAda file
Ada file
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 

Andere mochten auch

Questionnaire research
Questionnaire researchQuestionnaire research
Questionnaire research
JamesMarshallCHS
 
Ümran sunum new 2
Ümran sunum new 2Ümran sunum new 2
Ümran sunum new 2
enesummu
 
MH Resume 042115
MH Resume 042115MH Resume 042115
MH Resume 042115
Mahmood Hasan
 
Programma completo palermo apre le porte
Programma completo palermo apre le porteProgramma completo palermo apre le porte
Programma completo palermo apre le porte
Viviana Monaco
 
MCT_CERTIFICATE_Livingston
MCT_CERTIFICATE_LivingstonMCT_CERTIFICATE_Livingston
MCT_CERTIFICATE_Livingston
Richard Livingston
 
àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...
àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...
àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...
àžȘàž­àžšàž„àžŁàžčàž”àž­àž—àž„àž­àžĄ àč€àž§àč‡àžšàč€àž•àžŁàž”àžąàžĄàžȘàž­àžš
 
Daniel R.P actual
Daniel R.P actualDaniel R.P actual
Daniel R.P actual
Danno Piiio
 
T p1 ernesto vega
T p1 ernesto vegaT p1 ernesto vega
T p1 ernesto vega
Jabucho Vega
 

Andere mochten auch (20)

Showcase
ShowcaseShowcase
Showcase
 
Questionnaire research
Questionnaire researchQuestionnaire research
Questionnaire research
 
information diet
information dietinformation diet
information diet
 
LibGuides 2 Team Meeting - April 22, 2015
LibGuides 2 Team Meeting - April 22, 2015LibGuides 2 Team Meeting - April 22, 2015
LibGuides 2 Team Meeting - April 22, 2015
 
Ümran sunum new 2
Ümran sunum new 2Ümran sunum new 2
Ümran sunum new 2
 
La amistad......
La amistad......La amistad......
La amistad......
 
Final Grant
Final GrantFinal Grant
Final Grant
 
George &amp; aina g
George &amp; aina gGeorge &amp; aina g
George &amp; aina g
 
MH Resume 042115
MH Resume 042115MH Resume 042115
MH Resume 042115
 
Planning images
Planning imagesPlanning images
Planning images
 
Programma completo palermo apre le porte
Programma completo palermo apre le porteProgramma completo palermo apre le porte
Programma completo palermo apre le porte
 
R m g
R m gR m g
R m g
 
MCT_CERTIFICATE_Livingston
MCT_CERTIFICATE_LivingstonMCT_CERTIFICATE_Livingston
MCT_CERTIFICATE_Livingston
 
àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...
àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...
àžšàč‰àžČàž™àžȘàž­àžšàž„àžŁàžč (àž­.àžšàž§àžŁ) àžšàžŁàžŁàžąàžČàžąàžàžČàžŁàžšàžŁàžŽàž«àžČàžŁàž‡àžČàž™àčƒàž™àž«àž™àč‰àžČàž—àž”àčˆàčàž„àž°àžàžŽàž«àžĄàžČàžąàž›àžàžŽàžšàž±àž•àžŽàžŁàžČàžŠàžàžČàžŁàžȘàžłàž«àžŁàž±àžšàžœàžčàč‰...
 
Daniel R.P actual
Daniel R.P actualDaniel R.P actual
Daniel R.P actual
 
Aprenda a Lançar
Aprenda a LançarAprenda a Lançar
Aprenda a Lançar
 
Presentació english
Presentació english Presentació english
Presentació english
 
T p1 ernesto vega
T p1 ernesto vegaT p1 ernesto vega
T p1 ernesto vega
 
Promoting the Role of Government in Child Well-Being
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
 
Marina's song
Marina's songMarina's song
Marina's song
 

Ähnlich wie ADA FILE

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
C basics
C basicsC basics
C basics
MSc CST
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 

Ähnlich wie ADA FILE (20)

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Ds
DsDs
Ds
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
C programs
C programsC programs
C programs
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
C programms
C programmsC programms
C programms
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
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
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
C basics
C basicsC basics
C basics
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
Arrays
ArraysArrays
Arrays
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
C file
C fileC file
C file
 
C tech questions
C tech questionsC tech questions
C tech questions
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 

Mehr von Gaurav Singh (8)

Oral presentation
Oral presentationOral presentation
Oral presentation
 
srgoc dotnet_ppt
srgoc dotnet_pptsrgoc dotnet_ppt
srgoc dotnet_ppt
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
srgoc
srgocsrgoc
srgoc
 
Srgoc linux
Srgoc linuxSrgoc linux
Srgoc linux
 
Srgoc java
Srgoc javaSrgoc java
Srgoc java
 
cs506_linux
cs506_linuxcs506_linux
cs506_linux
 

KĂŒrzlich hochgeladen

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

KĂŒrzlich hochgeladen (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
BhubaneswarđŸŒčCall Girls Bhubaneswar ❀Komal 9777949614 💟 Full Trusted CALL GIRL...
BhubaneswarđŸŒčCall Girls Bhubaneswar ❀Komal 9777949614 💟 Full Trusted CALL GIRL...BhubaneswarđŸŒčCall Girls Bhubaneswar ❀Komal 9777949614 💟 Full Trusted CALL GIRL...
BhubaneswarđŸŒčCall Girls Bhubaneswar ❀Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 

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-