Research Area

Ashutosh Dubey

Tuesday, May 11, 2010

Array IIIrd Tutorial

11.WAP to accept a 2D array of 3*3 again accepts a number and prints its location in the array.


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x[3][3],n,i,j,c=0;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>x[i][j];
}
cout<<"The matrix is"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<x[i][j]<<" ";
cout<<endl;
}
cout<<"Enter the element"<<endl;
cin>>n;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(x[i][j]==n)
cout<<"The location is"<<i<<j;
else
c++;}}
if(c==9)
cout<<"The element not found";
getch();
}
12.WAP to perform addition of two matrix.
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int x[3][3],n[3][3],i,j,c[3][3];
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the matrix 1 :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>x[i][j];
}
cout<<"Enter the matrix 2 :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>n[i][j];
}
cout<<"sum of matrix are"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=x[i][j]+n[i][j];
cout<<c[i][j]<<" ";
}
cout<<endl;}
getch();
}

13.WAP to perform transposing of a matrix.




#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

int x[2][2],n[2][2],i,j;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the elements"<<endl;

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

{

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

{

cin>>x[i][j];

n[j][i]=x[i][j];

}

}

cout<<"The matrix is"<<endl;

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

{

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

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

cout<<endl;

}

cout<<"The elements after transpose"<<endl;

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

{

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

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

cout<<endl;

}

getch();

}

14.WAP to perform addition of diagonal element.



#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int x[2][2],i,j,s=0;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the elements"<<endl;

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

{

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

{

cin>>x[i][j];

if(i==j)

s+=x[i][j];

}

}

cout<<"The matrix is"<<endl;

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

{

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

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

cout<<endl;

}



cout<<"The sum of diagonal elements is"<<s;

getch();

}

15. WAP to accept 5 names from the user and greet him with welcome message.



#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char a[5][10],i,j;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the names"<<endl;

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

gets(a[i]);

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

{

Cout<<endl<<endl<<endl;

cout<<"Welcome ";

puts(a[i]);

}

getch();

}

By
Laxman
CSE
TITR Bhopal

No comments: