Subscribe to Feeds

Send Your COMPLETED Projects To georgepj@hotmail.com

We'll Publish It With Your Name :-)

Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]

Showing posts with label 1D Array. Show all posts
Showing posts with label 1D Array. Show all posts

No. of repetitions of a digit

Click Here To Download C++ File Of This Program

 //Downloaded From www.c4cpp.co.nr  
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
int i,j,c=1,l;
char a[100];
cout<<"Enter Array"<<endl;
cin.getline(a,100);
l=strlen(a);
for(i=0;i<l;i++)
{
c=1;
for(j=i+1;j<l;j++)
{
if(a[i]==a[j])
{
c=c+1;
a[j]=' ';
}
}
if(a[i]!=' ')
cout<<"Element"<<a[i]<<"is present"<<c<<"times"<<endl;
}
getch();
}

Insert & Delete from Array

Click Here To Download C++ File Of This Program

 //insert delete an element from array  
//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,x,c=0,e,ch,i,a[50],j;
cout<<"Enter Array lim"<<endl;
cin>>n;
cout<<"Enter array"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter Choice 1:Deletion 2Insertion"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter to be deleted"<<endl;
cin>>x;
for(i=0;i<n;i++)
{
if(a[i]==x)
{c++;
for(j=i;j<n;j++)
{
a[j]=a[j+1];
}
}
}
if(c==0)
cout<<"ENP"<<endl;
for(i=0;i<n-c;i++)
cout<<a[i]<<endl;
break;
case 2:
cout<<"Enter What & Where to be inserted"<<endl;
cin>>e>>x;
for(i=n;i>=x;i--)
a[i]=a[i-1];
a[x-1]=e;
for(i=0;i<=n;i++)
cout<<a[i]<<endl;
break;
}
getch();
}

Merge two Arrays

Click Here To Download C++ File Of This Program

//prg to merge arrays  
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
int c[100],i,j,k;
class merged
{
int na,nb,a[50],b[50];
public:
void merge();
void display();
void input();
}g;
void merged::merge()
{
int j=0;
int i=na-1;
while((i>0)&&(j<nb))
{
if (b[j]<a[i])
{
c[k]=a[i];
i--;
k++;
}
if (b[j]>a[i])
{
c[k]=b[j];
j++;
k++;
}
if (b[j]==a[i])
{
c[k]=b[j];
j++;
k++;
c[k]=a[i];
i--;
k++;
}
}
if(i==-1)
{
while(j<nb)
{
c[k]=b[j];
j++;
k++;
}
}
if(j==nb)
{
while(i>=0)
{
c[k]=a[i];
i--;
k++;
}
}
}
void merged::display()
{
for(i=0;i<na+nb;i++)
cout<<c[i];
}
void merged::input()
{
cout<<"Enter A Lim"<<endl;
cin>>na;
cout<<"Enter B Limit"<<endl;
cin>>nb;
cout<<"Enter array A"<<endl;
for(i=0;i<na;i++)
cin>>a[i];
cout<<"Enter Array B"<<endl;
for(j=0;j<nb;j++)
cin>>b[j];
}
void main()
{
clrscr();
g.input();
g.merge();
g.display();
getch();
}

Search ( Linear & Binary )

Click Here To Download C++ File Of This Program

 //linear and binary search 
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ch,l,u,mid,c=0,i,n,e,a[50];
cout<<"Enter the limit"<<endl;
cin>>n;
cout<<endl<<"Enter the elemnts"<<endl;
for(i=0;i<n;i++)
{
cout<<endl;
cin>>a[i];
}
cout<<"Enter the element to be searched for"<<endl;
cin>>e;
cout<<"Enter Your Choice 1:Linear 2:Binary Search";
cin>>ch;
switch(ch)
{
case 1 :
for(i=0;i<n;i++)
{
if(a[i]==e)
cout<<endl<<"Element is at "<<i+1<<" Position";
c=c+1;
}
if (c==0)
cout<<"Element Not Present";
break;
case 2:
c=0;
l=0;
u=n-1;
while(l<u)
{
mid=(l+u)/2;
if (a[mid]==e)
{
cout<<"Element is at "<<mid+1<<" Position "<<endl;
c++;
break;
}
if(e<a[mid])
u=mid-1;
if (e>a[mid])
l=mid+1;
}
if (c==0)
cout<<"Element not Present"<<endl;
break;
default :
cout<<"Wrong Choice"<<endl;
break;
}
getch();
}

Sorting ( Bubble, Selection, Insertion, Exchange )

Click Here To Download C++ File Of This Program

 //BUBBLE SELECTION SORT  
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int ch;
int i,j,x,k,z,l,m,n,o,p,a[50],small;
q :
cout<<"Enter the choice 1:Selection
2:Bubble 3:Exchange Selection
4:Insertion 5:Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the limit "<<endl;
cin>>n;
cout<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
cout<<endl;
}
for(j=0;j<n;j++)
{
small=a[j];
p=j;
for(i=j;i<n;i++)
{
if(small>a[i])
{
small=a[i];
p=i;
}
}
for(k=p;k>j;k--)
{
a[k]=a[k-1];
}
a[j]=small;
}
cout<<"Result"<<endl;
for(z=0;z<n;z++)
{
cout<<a[z];
cout<<endl;
}
goto q;
case 2:
cout<<"Enter the limit"<<endl;
cin>>n;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
for(j=0;j<n;j++)
{
for(i=0;i<n-1;i++)
{
if (a[i]>a[i+1])
{
x=a[i+1];
a[i+1]=a[i];
a[i]=x;
}
}
}
cout<<"Result"<<endl;
for (i=0;i<n;i++)
{
cout<<a[i];
cout<<endl;
}
break;
case 3 :
cout<<"Enter the limit "<<endl;
cin>>n;
cout<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
cout<<endl;
}
for(j=0;j<n;j++)
{
small=a[j];
p=j;
for(i=j;i<n;i++)
{
if(small>a[i])
{
small=a[i];
p=i;
}
}
a[p]=a[j];
a[j]=small;
}
cout<<"Result"<<endl;
for(z=0;z<n;z++)
{
cout<<a[z];
cout<<endl;
}
goto q;
case 4 :
int m=-32767;
cout<<"enter the no. of
elements"<<endl;
cin>>n;
cout<<"enter the array"<<endl;
for(i=1;i<=n;i++)
{cin>>a[i];}
a[0]=m;
for(i=1;i<=n;i++)
{for(j=0;j<i;j++)
{if(a[i]<a[j])
{p=a[i];
for(k=i-1;k>=j;k--)
{a[k+1]=a[k];}
a[j]=p;}}}
for(i=1;i<=n;i++)
{cout<<a[i];}
goto q;
case 5:
exit(0);
default:
cout<<"Wrong choice";
goto q;
}
getch();
}