Sie sind auf Seite 1von 16

/*

Program No
:1
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Practical List
:1
Date
: 9th April 2015
*/
#include<iostream.h>
#include<conio.h>
void Series()
{
int ch;
cout<<"Enter the correct index!"<<endl;
cout<<"1.Series 1(X+X^2+X^3...)\n2.Series 2(U+U^2/2!+U^3/3!...)"<<endl;
cout<<"3.Series 3(2+[2+4]+[2+4+6]...n terms)"<<endl;
cin>>ch;
switch(ch)
{
case 1:
{
long int N;
long float X,temp=1,sum=0;
cout<<"Enter the value of X:";
cin>>X;
cout<<"Enter the number of terms:";
cin>>N;
for(int i=1;i<=N;i++)
{
temp*=X;
sum+=temp;
}
cout<<"The sum of series 1 with X="<<X<<" and number of terms="<<N<<"
is:"<<sum<<endl;
break;
}
case 2:
{
long float U,temp=1,sum=0;
long int N;
cout<<"Enter the value of U:";
cin>>U;
cout<<"Enter the number of terms:";
cin>>N;

for(int i=1;i<=N;i++)
{
temp*=(U/i);
sum+=temp;
}
cout<<"The sum of series 2 with U="<<U<<" and number of terms="<<N<<"
is:"<<sum<<"\n";
break;
}
case 3:
{
long float temp=0,sum=0;
long int N;
cout<<"Enter the number of terms:";
cin>>N;
for(int i=2;i<=(2*N);i+=2)
{
temp+=i;
sum+=temp;
}
cout<<"The sum of series 3 with number of terms="<<N<<" is:"<<sum<<endl;
break;
}
default:cout<<"Invalid Input!";
}
}
void main()
{
clrscr();
cout<<"\t\t\t\tWelcome to series!"<<endl;
char ch;
for(int i=0;ch!='N';)
{
cout<<"Do you want to continue?(Y/N)"<<endl;
cin>>ch;
if(ch=='Y')
Series();
}
getch();
}

/*
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Date
: 20 April 2015
Program no
:2
Practical List
:1
*/
#include<iostream.h>
#include<conio.h>
void prime(int N)
{
int k=0;
for(int i=1;i<=N/2;i++)
if(N%i==0)
k++;
if(k==1)
cout<<N<<" is a prime number"<<endl;
else
cout<<N<<" is not a prime number"<<endl;
}
void palindrome(int N)
{
int temp=N,rev=0,temp1;
do
{
temp1=temp%10;
rev=rev*10+temp1;
temp=temp/10;
}
while(temp!=0);
if(rev==N)
cout<<N<<" is a palindrome number."<<endl;
else
cout<<N<<" is not a palindrome number."<<endl;
}
void even(int N)
{
int temp=N,sum=0,temp1;
do
{
temp1=temp%10;
sum+=temp1;
temp=temp/10;
}

while(temp!=0);
if(sum%2==0)
cout<<"The sum of digits of "<<N<<" is even."<<endl;
else
cout<<"The sum of digits of "<<N<<" is odd."<<endl;
}
void menu()
{
int ch;
cout<<"Choose the index corresponding to the desired option:"<<endl;
cout<<"1.To check whether a number entered by the user is prime or
not."<<endl;
cout<<"2.To check whether a number is a palindrome or not."<<endl;
cout<<"3.To check if the sum of the digits of a number entered by\n the user is
even or not."<<endl;
cin>>ch;
switch(ch)
{
case 1:
{
int N;
cout<<"Enter the desired number:";
cin>>N;
prime(N);
break;
}
case 2:
{
int N;
cout<<"Enter the desired number:";
cin>>N;
palindrome(N);
break;
}
case 3:
{
int N;
cout<<"Enter the desired number:";
cin>>N;
even(N);
break;
}
default:

{
cout<<"Invalid input!"<<endl;
}
}
}
void main()
{
clrscr();
cout<<"\t\t\t\tWelcome!!"<<endl;
char ch;
for(; ch!='N';)
{
cout<<"Do you want to continue?(Y/N)"<<endl;
cin>>ch;
if(ch=='Y')
menu();
else
cout<<"Goodbye";
}
getch();
}

/*
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Date
: 21 April 2015
Program no
:3
Practical List
:1
*/
#include<iostream.h>
#include<conio.h>
void input(int A[],int N)
{
cout<<"Enter the elements for the array!"<<endl;
for(int i=0;i<N;i++)
{
cout<<"A["<<i<<"]=";
cin>>A[i];
}
}
void display(int A[],int N)
{
cout<<"The array A is as follows!"<<endl;
for(int i=0;i<N;i++)
cout<<"A["<<i<<"]="<<A[i]<<endl;
}
void search(int A[],int N)
{
int search;
cout<<"Enter the element you want to search the array for:";
cin>>search;
int found=-1;
for(int i=0;i<N;i++)
if(A[i]==search)
found=i;
if(found!=-1)
cout<<search<<" was found at subscript "<<found<<" in the array!"<<endl;
else
cout<<search<<" is not there in the array!"<<endl;
}

void sort(int A[],int N)


{
for(int i=1;i<N;i++)
{
int Temp=A[i],j=i-1;
while(Temp<A[j]&&j>=0)
A[j+1]=A[j--];
A[j+1]=Temp;
}
cout<<"The sorted array is as follows!"<<endl;
display(A,N);
}
void main()
{
clrscr();
int A[100],N;
cout<<"Enter the size of the array:";
cin>>N;
input(A,N);
display(A,N);
search(A,N);
sort(A,N);
getch();
}

/*
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Date
: 21 April 2015
Program no
:4
Practical List
:1
*/
#include<iostream.h>
#include<conio.h>
void input(int A[],int N)
{
cout<<"Enter the elements for the array!"<<endl;
for(int i=0;i<N;i++)
{
cout<<"A["<<i<<"]=";
cin>>A[i];
}
}
void display(int A[],int N)
{
cout<<"The array A is as follows!"<<endl;
for(int i=0;i<N;i++)
cout<<"A["<<i<<"]="<<A[i]<<endl;
}
void search(int A[],int N)
{
int search;
cout<<"Enter the element to be searched for:";
cin>>search;
int LB=0,UB=N-1,MID,found=0;
while(LB<=UB&& !found)
{
MID=(LB+UB)/2;
if(A[MID]>search)
UB=MID-1;
else
if(A[MID]<search)
LB=MID+1;
else
found++;
}
cout<<search<<" was found at subscript "<<MID<<" in the array!"<<endl;
}

void sort(int A[],int N)


{
for(int i=0;i<N-1;i++)
{
int small=i;
for(int j=i+1;j<N;j++)
if(A[j]<A[small])
small=j;
if(small!=i)
{
int temp=A[small];
A[small]=A[i];
A[i]=temp;
}
}
cout<<"The sorted array is as follows:"<<endl;
}
void main()
{
clrscr();
int A[100],N;
cout<<"Enter the size of the array:";
cin>>N;
input(A,N);
display(A,N);
sort(A,N);
display(A,N);
search(A,N);
getch();
}

/*
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Date
: 21 April 2015
Program no
:5
Practical List
:1
*/
#include<iostream.h>
#include<conio.h>
void input(int A[][10],int N,int M)
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
{
cout<<"A["<<i<<"]["<<j<<"]=";
cin>>A[i][j];
}
}
void display(int A[][10],int N,int M)
{
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
cout<<A[i][j]<<" ";
cout<<endl;
}
}
void add(int A[][10],int B[][10],int C[][10],int N,int M, int R, int P)
{
if(N==R&&M==P)
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
C[i][j]=A[i][j]+B[i][j];
}
else
cout<<"Matrix addition is not defined!"<<endl;
}

void subtract(int A[][10],int B[][10],int C[][10],int N,int M, int R, int P)


{
if(N==R&&M==P)
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
C[i][j]=A[i][j]-B[i][j];
}
else
cout<<"Matrix subtraction is not defined!"<<endl;
}
void main()
{
clrscr();
int A[10][10],B[10][10],C[10][10],N,M,R,P;
cout<<"Enter the number of rows and columns for array A:";
cin>>N>>M;
cout<<"Enter the number of rows and columns for array B:";
cin>>R>>P;
cout<<"Enter values for array A:"<<endl;
input(A,N,M);
cout<<"Enter values for array B:"<<endl;
input(B,R,P);
add(A,B,C,N,M,R,P);
if(N==R&&M==P)
{
cout<<"The array obtained after addition is:"<<endl;
display(C,R,P);
}
subtract(A,B,C,N,M,R,P);
if(N==R&&M==P)
{
cout<<"The array obtained after subtraction is:"<<endl;
display(C,R,P);
}
getch();
}

/*
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Date
: 21 April 2015
Program no
:6
Practical List
:1
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int length(char A[])
{
int N=0;
for(int i=0;A[i]!='\0';i++)
N++;
return N;
}
void contents(char A[],int N)
{
int vowels=0,digits=0,consonants=0,special=0;
for(int i=0;i<N;i++)
if(A[i]=='A'||A[i]=='E'||A[i]=='I'||A[i]=='O'||A[i]=='U'||A[i]=='a'||A[i]=='e'||
A[i]=='i'||A[i]=='o'||A[i]=='u')
vowels++;
else
if((int)A[i]>=48&&(int)A[i]<=57)
digits++;
else
if((int)A[i]>=65&&(int)A[i]<=90)
consonants++;
else
if((int)A[i]>=97&&(int)A[i]<=122)
consonants++;
else
special++;
consonants+=vowels;
cout<<"The number of vowels in "<<A<<" are :"<<vowels<<endl;
cout<<"The number of consonants in "<<A<<" are :"<<consonants<<endl;
cout<<"The number of digits in "<<A<<" are :"<<digits<<endl;
cout<<"The number of special characters in "<<A<<" are :"<<special<<endl;
}

void reverse(char A[],int N)


{
char C[100];
for(int i=0;i<N;i++)
C[i]=A[N-1-i];
C[N]='\0';
cout<<"The reverse of the string is:"<<C<<endl;
}
void main()
{
clrscr();
char A[100];
cout<<"Enter a string:";
gets(A);
int N=length(A);
contents(A,N);
reverse(A,N);
getch();
}

/*
Developed by
: Karan Aggarwal, Kshitiz Agrawal, Kushagra Gupta
Date
: 21 April 2015
Program no
:7
Practical List
:1
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void input(char A[][100],int N)
{
for(int i=0;i<N;i++)
{
cout<<"Country "<<i+1<<":";
gets(A[i]);
}
}
void display(char A[][100],int N)
{
cout<<"The countries entered by the user:"<<endl;
for(int i=0;i<N;i++)
cout<<i+1<<".Country "<<i+1<<":"<<A[i]<<endl;
}
void sort(char A[][100],int N)
{
for(int i=0;i<N-1;i++)
{
int small=i;
for(int j=i+1;j<N;j++)
if(strcmpi(A[j],A[small])>0)
small=j;
if(small!=i)
{
char temp[100];
strcpy(temp,A[small]);
strcpy(A[small],A[i]);
strcpy(A[i],temp);
}
}
cout<<"Sorting in Descending Order is Complete!"<<endl;
}

void search(char A[][100],int N)


{
char search[100];
int pos=-1;
cout<<"Enter the country to be searched:";
cin>>search;
for(int i=0;i<N;i++)
if(strcmpi(A[i],search)==0)
pos=i;
if(pos!=-1)
cout<<"Country registered!"<<endl;
else
cout<<"Country not registered!"<<endl;
}
void main()
{
clrscr();
char A[100][100];
int N;
do
{
cout<<"Enter the number of countries you wish to enter:";
cin>>N;
}
while(N<=0||N>100);
input(A,N);
display(A,N);
sort(A,N);
display(A,N);
search(A,N);
getch();
}

Das könnte Ihnen auch gefallen