lalit oops

46
B.H.S.B.I.ETO OPS FILE SUBMITTED TO: SUBMITTED BY: Mrs. Kiran arora Lalit Mohan CSE(3 rd sem) Roll no. 90070302383 (9123) LALIT

Upload: vjndenne

Post on 22-Nov-2014

168 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lalit Oops

B.H.S.B.I.ETOOPS FILE

SUBMITTED TO: SUBMITTED BY: Mrs. Kiran arora Lalit Mohan

CSE(3rd sem)

Roll no. 90070302383

(9123)

A PROGRAM FOR HIGHER AND LOWER ELEMENTS OF ARRAY

#include<iostream.h>

LALIT

Page 2: Lalit Oops

#include<conio.h>

void main()

{

int a[5],i,j,n,k;

cout<<"enter no of elements from which we have to find ";

cin>>n;

cout<<"enter array elements "<<endl;

for(i=0; i<n; i++)

{

cin>>a[i];

}

for(i=0; i<n; i++)

{

for(j=i; j<n; j++)

{

if(i!=j)

{

if (a[i]>a[j])

{

int temp;

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

LALIT

Page 3: Lalit Oops

}}

cout<<”lowest element is “<<a[0];

cout<<”highest element is ”<<a[4];

}

PROGRAM FOR ADDITION OF MATRIC'S

LALIT

Page 4: Lalit Oops

#include<iostream.h>

#include<conio.h>

void main()

{

int m,n,i,j;

int a[20][20],b[20][20];

cout<<"Enter number of rows"<<endl;

cin>>m;

cout<<"enter no of colums";

cin>>n;

cout<<"Enter first Matrix : "<<endl;

for(i=1; i<=m; i++)

{ for(j=1; j<=n; j++)

{ cin>>a[i][j];}

}

cout<<endl;

cout<<"Enter second matrix : "<<endl;

for(i=1; i<=m; i++)

{ for(j=1; j<=n; j++)

{ cin>>b[i][j];}

}

cout<<"* First Matrix is : "<<endl;

for(i=1; i<=m; i++)

{

LALIT

Page 5: Lalit Oops

for(j=1; j<=n; j++)

{

cout<<a[i][j]<<" ";

}

cout<<endl;

}

cout<<endl<<"* Second Matrix is : "<<endl;

for(i=1; i<=m; i++)

{

for(j=1; j<=n; j++)

{

cout<<b[i][j]<<" ";

}

cout<<endl;

}

int c[20][20];

cout<<endl<<" ** The sum of the matrices is : "<<endl;

for(i=1; i<=m; i++)

{ for(j=1; j<=n; j++)

{ c[i][j]=a[i][j]+b[i][j];

cout<<c[i][j]<<" ";}

cout<<endl;

}}

LALIT

Page 6: Lalit Oops

A PROGRAM TO CALCULATE TOTAL CHARACTAR OF STRING

LALIT

Page 7: Lalit Oops

#include<iostream.h>

#include<conio.h>

void main()

{

int c=0,i=0;

char a[50];

cout<<"enter the string"<<" ";

cin>>a;

for(i=0;a[i]!='\0';++i)

{

if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))

{

++c;

}

else

{

continue;

}

}

cout<<"total number of characters in string "<<c;

getch();

}

LALIT

Page 8: Lalit Oops

LALIT

Page 9: Lalit Oops

A PROGRAM TO PRINT PRIME NUMBER

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,n,j;

cout<<"Enter extreme value : ";

cin>>j;

for(n=2; n<=j; n++ )

{

for(i=2; i<=n; i++)

{

if(n%i==0){break;}// NOT a Prime number !

else if(i==n-1)

{

cout<<n<<endl;

}//Prime number !

}

}

getch();

}

LALIT

Page 10: Lalit Oops

LALIT

Page 11: Lalit Oops

A PROGRAM FOR PRODUCT OF DOUBLE MATRICES

#include<iostream.h>

#include<conio.h>

void main()

{

int m,n,o,i,j;

int a[10][10], b[10][10];

cout<<"Enter number of rows for Ist Matrix : ";

cin>>m;

cout<<"Enter no. of columns of Ist Mtrx (= columns of IInd Mtrx) : ";

cin>>n;

cout<<"Enter no. of columns for IInd Mtrx : ";

cin>>o;

cout<<"Enter first Matrix : "<<endl;

for(i=1; i<=m; i++)

{

for(j=1; j<=n; j++)

{

cin>>a[i][j];

}}

cout<<"Enter Second Matrix : "<<endl;

for(i=1; i<=n; i++)

{

for(j=1; j<=o; j++)

LALIT

Page 12: Lalit Oops

{

cin>>b[i][j];

}}

cout<<"* First Matrix is : "<<endl;

for(i=1; i<=m; i++)

{

for(j=1; j<=n; j++)

{

cout<<a[i][j]<<" ";

}

cout<<endl;

}

cout<<"* Second Matrix is : "<<endl;

for(i=1; i<=n; i++)

{

for(j=1; j<=o; j++)

{

cout<<b[i][j]<<" ";

}

cout<<endl;

}

cout<<"The product of two Matrices is : "<<endl;

int c[10][10];

for(i=1; i<=m; i++)

{

LALIT

Page 13: Lalit Oops

for(j=1; j<=o; j++)

{

for(int k=1; k<=n; k++)

{

c[i][j]=c[i][j]+(a[i][k]* b[k][j]);

}cout<<c[i][j]<<" ";

}

cout<<endl;}

}

LALIT

Page 14: Lalit Oops

PROGRAM FOR FACTORIAL OF GIVEN NUMBER

A#include<iostream.h>

#include<conio.h>

main()

{

int i,k=1,n;

clrscr();

cout<<"enter any number ";

cin>>n;

for(i=1;i<=n;i++)

{

k=k*i;

cout<<"factorial of "<<i<<" is = ";

cout<<k<<endl;

}

k=1;

}

getch();

LALIT

Page 15: Lalit Oops

LALIT

Page 16: Lalit Oops

A PROGRAM FOR SUM OF ARRAY

#include<iostream.h>

#include<conio.h>

void main()

{

int temp=0,a[50],i,n;

cout<<"enter no of elements in array ";

cin>>n;

for(i=1;i<=n;i++)

{

cin>>a[i];

}

for(i=1;i<=n;i++)

{

temp=temp+a[i];

}

cout<<"sum of array elements is"<<temp;

getch();

}

LALIT

Page 17: Lalit Oops

LALIT

Page 18: Lalit Oops

A PROGRAM TO CONVERT TEMPERATURE IN FARENHIET TO CELSIUS

#include<iostream.h>

#include<conio.h>

void main()

{

int cels,n;

cout<<"enter temprature in farenhiet"<<endl;

cin>>n;

cels=(n-32)/1.8;

cout<<"temprature in celsius is"<<endl<<cels;

getch();

}

LALIT

Page 19: Lalit Oops

A PROGRAM FOR COMBINATION FORMULA

#include<iostream.h>

#include<conio.h>

main()

{

int i,n,r,c,j=1,k=1,h=1;

cout<<"formulae of combination is"<<endl;

cout<<"----n! / r! (n-r)!------ "<<endl;

cout<<"enter value of n"<<" ";

cin>>n;

cout<<"enter value of r"<<" ";

cin>>r;

for(i=1;i<=n;i++)

{

j=j*i;

}

for(i=1;i<=r;i++)

{

k=k*i;

}

for(i=1;i<=n-r;i++)

LALIT

Page 20: Lalit Oops

{

h=h*i;

}

c=j/(k*h);

cout<<c;

}

LALIT

Page 21: Lalit Oops

A PROGRAM FOR STORING ADDRESS OF ELEMENT IN ARRAY

#include<iostream.h>

#include<conio.h>

void main()

int a[50],i,n;

cout<<"enter no of elements in array";

cin>>n;

for(i=1;i<=n;i++)

{

cin>>a[i];

}

for(i=1;i<=n;i++)

{

cout<<"array element is "<<a[i]<<" "<<"and its adress is"<<&a[i]<<endl;

}

getch();

}

LALIT

Page 22: Lalit Oops

LALIT

Page 23: Lalit Oops

A PROGRAM FOR SORTING STRING ELEMENTS

#include<iostream.h>

#include<conio.h>

Void main()

{

int i,j,temp,n;

char a[7];

cout<<"enter string to be sorted ";

for(i=1;i<=7;i++)

{

cin>>a[i];

}

for(i=1;i<7;i++)

{

for(j=1;j<=7;j++)

{

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

} }

cout<<"string according to alphabetical order"<<endl;

LALIT

Page 24: Lalit Oops

for(i=1;i<=7;i++)

{

cout<<a[i]<<" ";

}

LALIT

Page 25: Lalit Oops

A PROGRAM FOR ADDITION OF TWO MATRICES

#include<iostream.h>

#include<conio.h>

void main()

{

int m,n,i,j;

int a[20][20],b[20][20];

cout<<"Enter number of rows"<<endl;

cin>>m;

cout<<"enter no of colums";

cin>>n;

cout<<"Enter first Matrix : "<<endl;

for(i=1; i<=m; i++)

{ for(j=1; j<=n; j++)

{ cin>>a[i][j];}

}

cout<<endl;

cout<<"Enter second matrix : "<<endl;

for(i=1; i<=m; i++)

{ for(j=1; j<=n; j++)

{ cin>>b[i][j];}

}

cout<<"* First Matrix is : "<<endl;

LALIT

Page 26: Lalit Oops

for(i=1; i<=m; i++)

{

for(j=1; j<=n; j++)

{

cout<<a[i][j]<<" ";

}

cout<<endl;

}

cout<<endl<<"* Second Matrix is : "<<endl;

for(i=1; i<=m; i++)

{

for(j=1; j<=n; j++)

{

cout<<b[i][j]<<" ";

}

cout<<endl;

}

int c[20][20];

cout<<endl<<" ** The sum of the matrices is : "<<endl;

for(i=1; i<=m; i++)

{ for(j=1; j<=n; j++)

{ c[i][j]=a[i][j]+b[i][j];

cout<<c[i][j]<<" ";}

cout<<endl;

LALIT

Page 27: Lalit Oops

}}

LALIT

Page 28: Lalit Oops

A PROGRAM FOR REVERSING THE ELEMENTS

#include<iostream.h>

#include<conio.h>

void main()

{

int rev,j,n;

cout<<"enter any five digit number "<<endl;

cin>>n;

cout<<"number in reverse form is"<<endl;

while(n>0)

{

rev=n%10;

cout<<rev;

n=n/10;

}

getch();

}

LALIT

Page 29: Lalit Oops

LALIT

Page 30: Lalit Oops

A PROGRAM FOR CHECKING MULTIPLE OF NUMBERS

#include<iostream.h>

#include<conio.h>

void main()

{

int i,n;;

cout<<"enter first number "<<endl;

cin>>n;

cout<<"enter second number"<<endl;

cin>>i;

if(n%i==0)

cout<<n<<" is a multiple of "<<i;

else

cout<<n<<" is not a multiple of "<<i;

getch();

}

LALIT

Page 31: Lalit Oops

LALIT

Page 32: Lalit Oops

A PROGRAM TO CHECK IF STRING IS PALINDROME OR NOT

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char n[50];

cout<<"enter any string"<<endl;

cin>>n;

strrev(n);

cout<<"string after reverse is"<<endl<<n;

getch();

}

LALIT

Page 33: Lalit Oops

LALIT

Page 34: Lalit Oops

A PROGRAM TO PRINT REVERSE OF STRING

#include<iostream.h>

#include<conio.h>

void main()

{

int rev,j,n;

cout<<"enter any five digit number "<<endl;

cin>>n;

cout<<"number in reverse form is"<<endl;

while(n>0)

{

rev=n%10;

cout<<rev;

n=n/10;

}

getch();

}

LALIT

Page 35: Lalit Oops

LALIT

Page 36: Lalit Oops

A PROGRAM TO CHECK MULTIPLE OF NO.

#include<iostream.h>

#include<conio.h>

void main()

{

int i,n;;

cout<<"enter first number "<<endl;

cin>>n;

cout<<"enter second number"<<endl;

cin>>i;

if(n%i==0)

cout<<n<<" is a multiple of "<<i;

else

cout<<n<<" is not a multiple of "<<i;

getch();

}

LALIT

Page 37: Lalit Oops

LALIT

Page 38: Lalit Oops

A PROGRAM TO PRINT REVERSE STRING

#include<iostream.h>

#include<conio.h>

void main()

{

int rev,j,n;

cout<<"enter any five digit number "<<endl;

cin>>n;

cout<<"number in reverse form is"<<endl;

while(n>0)

{

rev=n%10;

cout<<rev;

n=n/10;

}

getch();

}

LALIT

Page 39: Lalit Oops

LALIT

Page 40: Lalit Oops

A PROGRAM TO CHECK IF STRING IS PALINDROME OR NOT

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char n[50];

cout<<"enter any string"<<endl;

cin>>n;

strrev(n);

cout<<"string after reverse is"<<endl<<n;

getch();

}

LALIT

Page 41: Lalit Oops

A PROGRAM OF SERIES x+x^2/2+x^3/3…..

#include<iostream.h>

#include<conio.h>

#include<math.h>

main()

{

int n,i,j=1,k;

float c;

cout<<"enter value of x ";

cin>>n;

for(i=1;i<=5;i++)

{

if(i%2!=0)

{

j=j*i;

c=pow(n,i)/j;

} }

cout<<"result of given expression "<<c;

getch();

}

LALIT

Page 42: Lalit Oops

LALIT

Page 43: Lalit Oops

A PROGRAMMNING SHOWS A PALINDROME OR NOT

#include<iostream.h>

#include<conio.h>

main()

{

int a,temp,d,rev=0;

clrscr();

cout<<"enter any number ";

cin>>a;

temp=a;

while(temp>0)

{

d=temp%10;

temp/=10;

rev=rev*10+d;

}

if(rev==a)

cout<<a<<"is palindrome";

else

cout<<a<<" is not palindrome";

getch();

}

LALIT

Page 44: Lalit Oops

LALIT