Friday, May 17, 2013

show current computer time program in C++



#include <iostream>
#include <ctime>
using namespace std;

int main( )
{
   // current date/time based on current system
   time_t now = time(0);
 
   // convert now to string form
   char* dt = ctime(&now);
   cout << "The local date and time is: " << dt;
   // convert now to tm struct for UTC
   tm *gmtm = gmtime(&now);
   dt = asctime(gmtm);
   cout << "\nThe UTC date and time is:"<< dt << endl;
}

Friday, May 03, 2013

binary search in C++


//binary search
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
   
    int n;
    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];
}
int m;
int c,f,mid;
c=1;
f=n+1;
mid=(c+f)/2;
    cout<<"enter a element you want to search :";
    cin>>m;
    while(c<=f && bc[mid]!=m)
 {   if (m<bc[mid])
   f=mid-1;
    else {
    c=mid+1;  }
    mid = (c+f)/2;
}
if(f>=c){

 cout<<"the element is located in mid";
}
else
{

    cout<<"the element is not located in mid";
}
    getch();
return 0;
}

TELL STAR OF USER in C++


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

 cout<<"\nEnter Date: ";
 cin>>date;
 cout<<"\nEnter Month: ";
 cin>>month;
 cout<<"\n\n";

if(month<=1 && date>=20)
 cout<<"Aquarius";
 else
if(month<=2 && date<=18)
 cout<<"Aquarius";
 else
 if(month<=2 && date>=19)
 cout<<"Pices";
 else
 if(month<=3 && date<=20)
 cout<<"Pices";
 else
 if(month<=3 && date>=21)
 cout<<"Aries";
 else
 if(month<=4 && date<=19)
 cout<<"Aries";
 else
 if(month<=4 && date>=20)
 cout<<"Taurus";
 else
 if(month<=5 && date<=20)
 cout<<"Taurus";
 else
 if(month<=5 && date>=21)
 cout<<"Gemini";
 else
 if(month<=6 && date<=20)
 cout<<"Gemini";
 else
 if(month<=6 && date>=21)
 cout<<"Cancer";
 else
 if(month<=7 && date<=22)
 cout<<"Cancer";
 else
 if(month<=7 && date>=23)
cout<<"Leo";
 else
 if(month<=8 && date<=22)
 cout<<"Leo";
 else
 if(month<=8 && date>=23)
 cout<<"Virgo";
 else
 if(month<=9 && date<=22)
 cout<<"Virgo";
 else
 if(month<=9 && date>=23)
 cout<<"Libra";
 else
 if(month<=10 && date<=22)
 cout<<"Libra";
 else
 if(month<=10 && date>=23)
 cout<<"Scorpio";
 else
 if(month<=11 && date<=21)
 cout<<"Scorpio";
 else
 if(month<=11 && date>=22)
 cout<<"Sagittarius";
 else
 if(month<=12 && date<=21)
 cout<<"Sagittarius";
 else
 if(month<=12 && date>=22)
 cout<<"Capricon";
 else
 if(month<=1 && date<=19)
 cout<<"Capricon";
 else
 cout<<"Invalid Month:";

 }

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--;
}
}

Wednesday, March 20, 2013

displayind odd numbers upto 100 in C++

#include <iostream.h>
#include <conio.h>
int main()
{
int i;
for(int i=1;i <= 100 ;i++)
{

 if(i%2==1)
cout<<i<<endl;
}
getch();
return 0;

}