C++ Lab 7 Alpha
C++ Lab 7 Alpha
This lab has been designed to practice programs of nested loops. We will also practice
handling arrays in c++ including array declaration, initialization and accessing array elements.
Clear concept about nested loops and arrays has already been provided in the class along with
examples.
Objectives:
In this lab, you will practice:
• Using nested loops to repeat actions on data of outer loop.
• Using nested loops to print multiple 2 D patterns.
• Array declaration and initialization.
• Inputting and printing array elements using loop.
12345 * * * * * * * * * *
1234 * * * * * * * * * *
123 * * * * * * * * * *
12 * * * * * * * * * *
1 * * * * * * * * * *
* * * * * * *
* * * * *
* * *
*
LAB MANUAL # 7
Course: Computer Programming (CP-107)
Session: 22CP (Alpha)
Question # 3: 3/
Write a program in C++ to input 20 values into an array. Find out and display odd and even
values entered in the array.
Question # 4: 3/
Write a program in C++ to input data into an array of 10 elements. Then ask the user to enter
a value from the keyboard and find out the location of the entered value in an array. If the
entered number is not found in the array, display the message “Number not found”. Also ask
the user whether he wants to use the program again or not.
Question # 5: 4/
Observe following codes and write their output. If there is any error in the code, then correct
it and write the output.
int main()
{
int a=1,b=1;
while(a<=6)
{
b=1;
while(b<=a)
{
cout<<"*";
b++;
}
cout<<endl;
a++;
}
int main()
{
int var = 'F';
for (int i = 5; i >= 1; i--)
{
for (int j = 0; j < i; j++)
cout<<char (i+var);
cout<<endl;
}
return 0;
}
int main()
{
int f_arr[5];
LAB MANUAL # 7
Course: Computer Programming (CP-107)
Session: 22CP (Alpha)
*****************