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

Assignmwnt

Uploaded by

pakistanhello51
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignmwnt

Uploaded by

pakistanhello51
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

TASK 1:

#include<iostream>
using namespace std;
swap(int &a,int &b)
{
int temp=a;
a=b;
b=temp;
}
int main()
{
int n;
cout<<"Enter no. elements of array: ";cin>>n;
int i,j, arr[n];
for(int i=0;i<n;i++)
{
cout<<"Enter values of array: ";
cin>>arr[i];
}
cout<<"Descending order: ";
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(arr[i]<arr[j])
swap(arr[i],arr[j]);
}
}
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
int lar;
cout<<"\nEnter nth largest (value of n): ";cin>>lar;
if(lar>n)
cout<<"Invalid entry.";
else
cout<<"\n"<<lar<<"th largest element is: "<<arr[lar-1];
return 0;
}

TASK 2:
#include<iostream>
using namespace std;
swap(int &a,int &b)
{
int temp=a;
a=b;
b=temp;
}
int main()
{
int n,count=0,number;
cout<<"Enter no. elements of array: ";cin>>n;
int i,j, arr[n];
for(int i=0;i<n;i++)
{
cout<<"Enter values of array: ";
cin>>arr[i];
}
cout<<"Acending order: ";
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
swap(arr[i],arr[j]);
}
}
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
cout<<"\nEnter number to check recurrance: ";cin>>number;
for(int i=0;i<n;i++)
{
if(arr[i]==number)
{
count++;
}
}
cout<<"Recurrance value of "<<number<<" is: "<<count;
}
TASK 3:
#include<iostream>
using namespace std;
int main()
{
int n;
char ch;
cout<<"Enter 's' to inverse string and 'i' to inverse integer: ";cin>>ch;
cout<<"Enter no. elements of array: ";cin>>n;
if(ch=='i'){
int i, arr[n];
for(int i=0;i<n;i++)
{
cout<<"Enter values of array: ";
cin>>arr[i];
}
cout<<"Reversed array: ";
for(int i=n-1;i>=00;i--)
cout<<arr[i];
}
if(ch=='s')
{
int i;
char arr[n];
for(int i=0;i<n;i++)
{cout<<"Enter values of array: ";cin>>arr[i];
}
cout<<"Reversed array: ";
for(int i=n-1;i>=0;i--)
cout<<arr[i];
}}

TASK 4:
#include<iostream>
using namespace std;
int main()
{
int i,a;
int arr[32],b;
cout<<"Enter number to be converted: ";cin>>a;
for(i=0;a>0;i++){
arr[i]=a%2;
a=a/2;
}
cout<<"Binary conversion= ";
for(int j=i-1;j>=0;j--)
{
cout<<arr[j];
}
}

TASK 6:
#include<iostream>
using namespace std;
int main()
{
int n;
char ch;
cout<<"Enter 's' to inverse string and 'i' to inverse integer: ";cin>>ch;
cout<<"Enter no. elements of array: ";cin>>n;
if(ch=='i'){
int i, arr[n];
for(int i=0;i<n;i++)
{
cout<<"Enter values of array: ";
cin>>arr[i];
}
cout<<"Reversed array: ";
for(int i=n-1;i>=00;i--)
cout<<arr[i];
}
if(ch=='s')
{
int i;
char arr[n];
for(int i=0;i<n;i++)
{cout<<"Enter values of array: ";cin>>arr[i];
}
cout<<"Reversed array: ";
for(int i=n-1;i>=0;i--)
cout<<arr[i];
}}

You might also like