Usama Lab 6
Usama Lab 6
(Sahiwal campus)
FA19-BEE-010
In Lab Exercises
Submitted To:
Mr. Hammid
Submitted By:
I stated it with immense pleasure you have taught and allowed me to make an
assignment, which helped me in building my writing skills.
In-Lab Exercise
Example # 1. Here in the loop initialization part I have set the value of variable i to
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
cout<<"Enter a value=";
cin>>i;
for (int m=1;m<=6;m++)
{
cout<<"Value of variable="<<m<<endl;
}
getch();
}
2
Introduction to Computer Programming (LAB) FA19-BEE-010
Exercise #1. Write a program in C++ using for loop to display the table of your roll
number.
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
cout<<"enter a number=";
cin>>i;
{
for (j=1;j<=10;j++)
cout<<i*j<<endl;
}
getch();
}
3
Introduction to Computer Programming (LAB) FA19-BEE-010
Exercise # 2. Write a program in C++ using for loop to display the following output.
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for (i=1;i<=5;i++)
{
for (j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
getch();
}
4
Introduction to Computer Programming (LAB) FA19-BEE-010
Question # 1 Write a Program that input a number for table from the user. And also
input length for table. And shows the table according to its length.
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
cout<<"enter a number=";
cin>>i;
{
for (j=1;j<=10;j++)
cout<<i*j<<endl;
}
getch();
}
5
Introduction to Computer Programming (LAB) FA19-BEE-010
Question # 2: Write a Program that Shows the first 100 odd number on the console.
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for (i=1;i<=5;i++)
{
for (j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
getch();
}
6
Introduction to Computer Programming (LAB) FA19-BEE-010
Question #3 Write a Program that display the following output on the console.
(A)
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
cout<<"enter a number=";
cin>>k;
{
for (i=1;i<=k;i++)
{
for (j=1;j<=k-i;j++)
cout<<" ";
}
while (k!=2*i)
cout<<"*";
cout<<endl;
}
getch();
}
7
Introduction to Computer Programming (LAB) FA19-BEE-010
(B)
Algorithm: - Result
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
cout<<"enter a number=";
cin>>k;
{
for (i=1;i<=k;i++)
{
for (j=1;j<=k-i;j++)
cout<<" ";
}
while (k!=2*i-1)
cout<<"*";
cout<<endl;
}
getch();
}