Computer Programming Lab Lab Journal - 5: Objective
Computer Programming Lab Lab Journal - 5: Objective
Lab Journal - 5
Name: _________________________________
Enrollment #: _________________________________
Date: ________________________________
Objective:
1) Understanding Looping Statements
2) Practicing for repetition structures
3) Practicing nested for repetition structures
Tools Required:
int j, square;
for (j = 0; j < 15; j++)
{
square = j * j;
cout << " square is : " <<square;
cout << endl;
}
While:
int j, square;
j = 0;
while (j < 15)
{
square = j * j;
cout << " square is : " << square;
cout << endl;
j++;
}
Do-While:
int j, square;
j = 0;
do
{
square = j * j;
cout << " square is : " << square;
cout << endl;
j++;
} while (j < 15);
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int num = 1;
for(; num <= 10;)
{
4. #include<iostream> Description:
#include<conio.h>
using namespace std;
void main()
{
for(int i=1;i<=2;i++) Output:
{
for(int j=1;j<=2;j++)
{
for(int k=1;k<=3;k++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
getch();
}
5. Convert the following do-while loop to a Write Code through for loop here:
for loop, only initialize the loop
variable in the initialization part
int cube = 1;
int numb = 1;
do
{
cube = numb * numb * numb;
cout<< “ Number is: “ <<numb;
cout<< “ Cube is:
“<<cube<<endl;
numb++;
} while( numb < 30);
Task 2: Write a C++ program using for loop, that takes a number from the user and displays its
table till 10 multiples. Output should be in the form 2 x 1 = 2
Task 3:
Write a program using for loop to extract even number from the range of integers given from the
keyboard and then print them on the screen. Your program output should be something like:
Input starting integer: 6
Input ending integer: 12
Even numbers are: 6 8 10 12
Task 4: Write a C++ program using nested for loop to print the following pyramid.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Task 5: Write a C++ program using nested for loop to print the following pyramid.
*
**
***
****
*****
******
Task 6: Write a C++ program using nested for loop to print the following pyramid.
54321
54321
54321
54321
54321
Task 7: Write a C++ program using nested for loop to print the following pyramid.
*
***
*****
*******
*********
****************************************************