0% found this document useful (0 votes)
6 views

Week 5 Assignment

Uploaded by

iirwed79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Week 5 Assignment

Uploaded by

iirwed79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

#1

Write a c++ program to print the max value in an array?

#include <iostream>
using namespace std;
int main()
{
int m[5];
for (int i=0; i<5; i++)
{
cout<<"Enter element #"<<i+1<<endl;
cin>>m[i];
}
int max=m[0];
for(int i=1; i<5; i++)
{
if(m[i]>max)
{
max=m[i];
}
}
cout<<"Max is : "<<max;
}
#2

Write a c++ program to print the min in an array?

#include <iostream>
using namespace std;
int main()
{
int m[5];
for (int i=0; i<5; i++)
{
cout<<"Enter element #"<<i+1<<endl;
cin>>m[i];
}
int min=m[0];
for(int i=1; i<5; i++)
{
if(m[i]<min)
{
min=m[i];
}
}
cout<<"Min is : "<<min;
}

#3

Write a c++ program to search for an item in an array?

#include <iostream>
using namespace std;
int main()
{
int m[5],i,f;
cout<<"Enter five numbers for search : "<<endl;

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


{
cin>>m[i];
}
cout<<"Enter a number for search : "<<endl;
cin>>f;
for(i=1; i<5; i++)
{
if(m[i]==f)
{
break;
}
}
if(i==5)
cout<<"Not found";
else
cout<<"Found at Position : "<<i+1;
}

#4

Write a c++ program to swap two arrays?

#include <iostream>
using namespace std;
int main()
{
int M[5],N[5],i;
cout<<"Enter First Array : "<<endl;
for (int i=0; i<5; i++)
{
cin>>M[i];
}
cout<<"Enter Second Array : "<<endl;
for (int i=0; i<5; i++)
{
cin>>N[i];
}
for(i=0; i<5; i++)
{
int temp=N[i];
N[i]=M[i];
M[i]=temp;
}
cout<<"First Array : "<<endl;
for(i=0; i<5; i++)
{
cout<<M[i]<<" ";
}
cout<<"Second Array : "<<endl;
for(i=0; i<5; i++)
{
cout<<N[i]<<" ";
}
}

#5

Write a c++ program to print two-dimensional array?

#include <iostream>
using namespace std;
int main()
{
int m[3][3],row,col;
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
cin>>m[row][col];
}
}
for(row=0; row<3; row++)
{
for(col=0; col<3; col++)
{
cout<<m[row][col]<<" ";
}
}
}

#6

Write a c++ program using simple pointer?

#include <iostream>
using namespace std;
int main()
{
int *p, a[5]={2,3,4,5,6};
p=&a[1];
p++;
cout<<*p;
}

You might also like