Lab 10
Lab 10
Task 1:
#include <iostream>
int main()
{
int num[10] = { 11,12,13,14,15,16,17,18,19,20 };
int i;
for (i = 0; i <= 9; i++)
{
cout << num[i] << endl;
}
return 0;
}
Result:
Task 2(a):
#include <iostream>
int main()
{
int i;
int num;
int z[10];
cout << "Enter num = ";
cin >> num;
cout << "Enter" << num << "numbers = ";
for (i = 0; i<num; i++)
{
cin >> z[i];
}
cout << "Even numbers = ";
for (i = 0; i<num; i++) {
if (z[i] % 2 == 0)
cout << " " << z[i];
}
cout << "Odd numbers = ";
for (i = 0; i<num; i++)
{
if (z[i] % 2 == 1)
cout << " " << z[i];
}
return 0;
}
Result:
Task 2(b):
#include <iostream>
int main()
{
int z[10];
cout << "Enter 10 values = ";
for (int i = 0; i <= 9; i++)
{
cin >> z[i];
}
cout << endl;
cout << "Values on even index = ";
for (int j = 0; j <= 9; j++)
{
if (j % 2 == 0)
cout << z[j] << endl;
}
cout << "Values on odd index = ";
for (int k = 0; k <= 9; k++)
{
if (k % 2 != 0)
cout << z[k] << endl;
}
return 0;
}
Result:
Task 3:
#include <iostream>
using namespace std;
int main()
{
int z;
cout << "Enter the size of array::";
cin >> z;
int Array[z];
for (int i = 0; i < z; i++)
Array[i] = rand() % 6 + 1; //Generate number between 0 to 6
cout << "\nElements of the array using random function :" << endl;
Result:
Task 4:
#include<iostream>
using namespace std;
int main()
{
int num[20], count = 1, search;
for (int i = 0; i <= 19; i++)
{
num[i] = count;
count++;
}
cout << "Enter number to search : \n";
cin >> search;
int j;
for (j = 0; j <= 19; j++)
{
if (num[j] == search)
{
cout << "The given number is present on the index " << j << endl;
break;
}
}
if (num[j] != search)
cout << "-999\n";
system("pause");
return 0;
}
Result: