C++ Programme to sum the sequence x -(x^2/2!) + (x^4/4!) -(x^6/6!) + .......



#include<iostream.h>
#include<conio.h>
#include<math.h>

int main()
{
                int x,p,i,j;
                double fact=1.0,ans=0;
                cout<<"Enter the value of x:";
                cin>>x;
                cout<<"Enter till what power you want:";
                cin>>p;
                ans=x;
                for(i=2,j=1;i<=p;i++,j++){
                                fact=fact*i;
                                if(i%2==0)
                                                ans+=(pow(-1,j))*((pow(x,i))/(fact));
                }
                cout<<"The sum of the series is:"<<ans;
                return 0;
}


OUTPUT:

C++ Program to reverse the order of given names



#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
               clrscr();
               char *name[]={"anand","naureen","banjot","wahid","sheena"};
               int i,j;
               cout<<"\nOriginal string\n";
               for(i=0;i<5;i++)
                              cout<<name[i]<<endl;
               char *t;
               for(i=0,j=4;i<5/2;i++,j--)
               {
                              t=name[i];
                              name[i]=name[j];
                              name[j]=t;
               }
               cout<<"\nReversed string:\n";
               for(i=0;i<5;i++)
               cout<<name[i]<<endl;
               getch();
}

OUTPUT:

C++ programme to record a score of a cricket match. One array stores information of batting team such as batman's name, runs score ,etc. The other array stores information about bowling team. The program reads in above information and depending on user's choice, it displays either batting team's information or bowling team's information




#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct bat
{
char name[20],modeout[70], indica;
int runs, score, totruns, totove, xtras;
};

struct bowl
{
char name[20];
int ttvrs,rnsgvn,wktstkn;
};
void main()
{
clrscr();
int plno;
int plytyp;
bat pl1[3];
bowl pl2[3];



cout<<"Enter the batsmen details:"<<endl;
for (int i=0;i<3;i++)
{
cout<<"Enter name of player "<<i+1<<endl;
gets (pl1[i].name);
cout<<"enter the runs scored by player "<<i+1<<endl;
cin>>pl1[i].runs;
cout<<"Enter the overs played by the player"<<i+1<<endl;
cin>>pl1[i].totove;
cout<<"Enter the status of the player if out (N)or not(Y)"<<endl;
cin>>pl1[i].indica;
}



cout<<"Enter the bowlers details "<<endl;
for (i=0;i<3;i++)
{
cout<<"Enter the name of the bowler "<<i+1<<endl;
gets(pl2[i].name);
cout<<"Enter the runs given by the bowler "<<i+1<<endl;
cin>>pl2[i].rnsgvn;
cout<<"Enter the wickets taken by the bowler "<<i+1<<endl;
cin>>pl2[i].wktstkn;
cout<<"Enter the total overs played by the  bowler "<<i+1<<endl;
cin>>pl2[i].ttvrs;
}


cout<<"Thank you all details recd"<<endl;
xyz:
cout<<"Select between batsmen(1) or bowlers(2) to see their details"<<endl;
abc:
cin>>plytyp;


switch (plytyp)
{


case 1:
cout<<"Enter the batsman number to see his details "<<endl<<endl<<endl;
cin>>plno;
plno--;
cout<<"Batsman number :"<<plno+1<<endl;
cout<<"Batsman name :";
puts(pl1[plno].name);
cout<<"Runs scored by the batsman :"<<pl1[plno].runs<<endl;
cout<<"Total overs played by the batsman :"<<pl1[plno].totove<<endl;
cout<<"Player status out "<<pl1[plno].indica<<endl;
break;



case 2:
cout<<"Enter the bowlers number to see his details "<<endl<<endl<<endl;
cin>>plno;
plno--;
cout<<"Bowlers name :";
puts(pl2[plno].name);
cout<<"Runs given by the player is :"<<pl2[plno].rnsgvn<<endl;
cout<<"Total overs played by the player :"<<pl2[plno].ttvrs<<endl;
cout<<"Total wickets taken by the user :"<<pl2[plno].wktstkn<<endl;
break;


default:
cout<<"Idiot enter a decent value"<<endl;
goto abc;
}

cout<<endl<<endl<<endl<<"Do you wish to continue? Y-1 N-2"<<endl;
cin>>plno;
if (plno==1)
goto xyz;
else
cout<<"Thank you Press any key to exit";
getch();
}

output: