University of Engineering and Technology, Taxila: SRS Assignment 01
University of Engineering and Technology, Taxila: SRS Assignment 01
University of Engineering and Technology, Taxila: SRS Assignment 01
TECHNOLOGY, TAXILA
SRS Assignment 01
Submitted to:
Engr. Rabia Arshad
Submitted by:
Mohtashim Ali
18-SE-63
#include<iostream>
using namespace std;
int even();
int odd();
int prime();
int cqn();
int main()
{
A:
int charr;
switch(charr){
case 1:
even();
cout<<endl<<endl<<endl;
break;
case 2:
odd();
cout<<endl<<endl<<endl;
break;
case 3:
prime();
cout<<endl<<endl<<endl;
break;
case 4:
cqn();
cout<<endl<<endl<<endl;
break;
default:
cout << "Invalid Command!!" << endl;
break;
}
goto A;
return 0;
}
int even()
{
int n,i,j;
int arr[n];
cout<<"Size of Array: ";
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";
for(i=0; i<n;i++)
{
cin>>arr[i];
}
cout<<"\nEven numbers :\t";
for(int i=0; i<n;i++)
{
if(arr[i]%2==0)
{
cout << arr[i] << "\t";
}
}
}
int odd()
{
int n,i,j;
int arr[n];
cout<<"Size of Array: ";
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";
for(i=0; i<n;i++)
{
cin>>arr[i];
}
cout<<"\nOdd numbers :\t";
for(int i=0 ; i<n ; i++)
{
if (arr[i] % 2 != 0)
{
cout << arr[i] << "\t";
}
}
}
int prime()
{
int n ,i,j;
int arr[n];
cout<<"Size of Array: ";
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";
for(i=0; i<n;i++)
{
cin>>arr[i];
}
cout << "\nPrime numbers :\t";
for( j=0 ; j<n ; j++){
for(i=2;i<arr[j];i++)
if(arr[j]%i==0)
break;
if(arr[j]==i && arr[j]>1 )
cout << arr[j] << "\t";
}
}
int cqn()
{
int m,n ,i,j;
int arr[n];
cout<<"Size of Array: ";
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";
for(i=0; i<n;i++)
{
cin>>arr[i];
}
cout << "\nComplete squares :\t";
for( j=0 ; j<n ; j++){
i=0;
m = i * i;
while (m < arr[j]){
i = i + 1;
m = i * i;
}
if (m == arr[j])
cout << arr[j] << "\t";
}
}
2-Write a c++ program to find duplicate values of an array of integer values.
#include<iostream>
using namespace std;
int main()
{
A:
int i, arr[20],j,n;
3-Write a c++ program to find the common elements between two arrays of integers.
#include<iostream>
using namespace std;
int main()
{
A:
int i, arr[20],j,n,m,num=0,arr1[20];
4-Write a c++ program to get the difference between the largest and smallest values in an array of
integers.
#include<iostream>
using namespace std;
int main()
{
int i,j,n, max , min , diff;
cout<<"Enter a size: ";
cin>>n;
int arr[n];
cout<<"Enter "<<n<<" Elements in array: ";
for(i=0;i<n;i++)
{
cin>>arr[i];
}
max=arr[0];
for(i=0;i<n;i++)
{
if(max<arr[i])
max=arr[i];
}
min=arr[0];
for(i=0;i<n;i++)
{
if(min>arr[i])
min=arr[i];
}
diff=max-min;
cout<<"\nDifference Between "<< max<<" and "<<min<<" is "<<diff<<endl;
}