0% found this document useful (0 votes)
16 views5 pages

Ubaid Assignmnent Itp Class

Itp assignment

Uploaded by

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

Ubaid Assignmnent Itp Class

Itp assignment

Uploaded by

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

ITP ASSIGNMENT

QUESTION NO 01
Write a C++ program to find out 2nd
largest number from an array.

INPUT:
int main()
{
int list[10], temp;

cout << "Enter 10 values:\n";

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


cin >> list[i];

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


{
for (int j = 0; j < 10 - i - 1; j++)
{
if (list[j] < list[j + 1])
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
cout << "Second Largest Value: " << list[1];

return 0;
}

OUTPUT:
QUESTION NO 02
Write a C++ program to separate
even and odd numbers in an array of
integers put all even numbers first and
then odd numbers.

INPUT:
#include<iostream>
using namespace std;

int main()
{
int list[10], temp;

cout << "Enter 10 values:\n";

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


cin >> list[i];

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


{
for (int j = 0; j < 10 - i - 1; j++)
{
if (list[j] % 2 != 0)
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
cout << "After seperating even first than odd:\n";

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


cout << list[i] << endl;

return 0;
}

OUTPUT:

QUESTION NO 03
Write a program to sort array of 0’s, 1’s and
2’s. Final array put all 0’s than all 1’s and all
2’s at last.

INPUT:
#include<iostream>
using namespace std;

int main()
{
int list[10] = { 0,1,2,0,1,2,0,1,2,0 };
int temp;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10 - i - 1; j++)
{
if (list[j] > list[j + 1])
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}

cout << "Sorted array:\n";

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


cout << list[i] << " ";

cout << endl;

return 0;
}

OUTPUT:

QUESTION NO 04
Write a C++ program to find 3rd
smallest value from an array having 10
elements.

INPUT:
#include<iostream>
using namespace std;

int main()
{
int list[10], temp;

cout << "Enter 10 values:\n";

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


cin >> list[i];

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


{
for (int j = 0; j < 10 - i - 1; j++)
{
if (list[j] > list[j + 1])
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
cout << "Third Smallest Value: " << list[2] << endl;

return 0;
}

OUTPUT:

You might also like