Friday, May 03, 2013

bubble sort in C++


#include<iostream>
using namespace std;
int main()
{
   
    int n,p;
    cout<<"enter the array length: ";
    cin>>n;
    int bc[n];
      for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is: ";
    cin>>bc[i];
}
for(int k=1;k<=n-1;k++)
{
       
        for(int p=1;p<=n-k;p++)
        {if(bc[p]>bc[p+1])
        bc[p]=bc[p+1];
}
}
for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is:"<<bc[i]<<endl;
            }
}

program to get ip address in C++


#include<stdlib.h>
main()
{
   system("C:\\Windows\\System32\\ipconfig");
   system("pause");
   return 0;
}

searching in linked list in C++


#include <iostream>
using namespace std;
struct node{
int data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim,item;
cout<<"enter the linked list limited :";
cin>>lim;
cout<<"ente item to find :";
cin>>item;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location"<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  if (item=ptr->data) {
cout<<"Item is found location of the item is "<<ptr->link;
return 0;
}
ptr=ptr->link;
}
}

General Linked list integer program in C++


#include <iostream>
using namespace std;
struct node{
int data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim;
cout<<"enter the linked list limited :";
cin>>lim;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location"<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  cout<<ptr->data<<endl;
      ptr=ptr->link;
}
}

General Linked list character program in C++


#include <iostream>
using namespace std;
struct node{
char data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim;
cout<<"enter the linked list limited :";
cin>>lim;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location "<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  cout<<ptr->data<<endl;
      ptr=ptr->link;
}
}


Friday, April 26, 2013

number in pyramid before space in C++


#include <iostream>
using namespace std;
int main(){

int a;
int b;
cout<<"enter the number pyramid limit:";
cin>>b;
int nPyramid = 1;

int k=b;
for(a=1;a<=k;a++)
{


for(int i=0;i<b;i++)
{                   //for the spaces
cout<<nPyramid<<"\t";

nPyramid++;         //Increase the pyramid value by 1
}

nPyramid--; //Remove this line and see the effect
cout<<endl; //Next line
for(int i=1;i<=a;i++)
{ cout<<"\t";
}
b--;
}
}
output:-

number in pyramid space after in C++


#include <iostream>
using namespace std;
int main(){
int a;
int b;
cout<<"enter the number pyramid limit:";
cin>>b;
int nPyramid = 1;
int k=b;
for(a=1;a<=k;a++)
{
for(int i=0;i<b;i++)
{                   //for the spaces
cout<<"\t"<<nPyramid;

nPyramid++;         //Increase the pyramid value by 1
}

nPyramid--;                 //Remove this line and see the effect
cout<<endl;               //Next line
b--;
}
}