C++ Lab 5
C++ Lab 5
C++ Lab 5
This lab has been designed to practice looping statements e.g., for loop, while loop and do-
while loop. Clear concept about this programming construct has already been provided in the
class. Supporting material can be found in section 3.3 of Problem solving with C++. Lab
handouts are also provided along with the lab manual as reference material.
Objectives:
In this lab, you will practice:
• Designing and using for loop statement.
• Designing and using while loop statement.
• Designing and using do while loop statement.
• Selecting appropriate loop type for given problem.
Write a C++ program to calculate the approximate value of pi using this series. The program
takes an input n that determines the number of terms in the approximation of the value of pi
and outputs the approximation.
Question # 6: 3/
Observe output of the following codes and rewrite them to fix the problem (if any).
a. int main()
{
for(int i=0;i<10;i++)
cout<<i<<endl;
cout<<i+5;
return 0;
}
b. int main()
{
int i=0;
while(i<10);
{
cout<<i<<endl;
i++;
}
return 0;
}
c. int main()
{
for(int j=0;j<10;j--)
cout<<j<<endl;
return 0;
}
***************