0% found this document useful (0 votes)
8 views6 pages

Lab 6

C++ codes for nested loops and patterns

Uploaded by

rayyanquddusi683
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Lab 6

C++ codes for nested loops and patterns

Uploaded by

rayyanquddusi683
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Computer Fundamental and

Programming
CIS-101
Fall 2022
Lab Report no. 6
Obtained Marks
Total Marks

Lab Engineer Signature &


Comments

Student Name
RAYYAN QUDDUSI

Section:
Experiment No: 6 Date of Submission:

Experiment Title: FOR LOOP


[Title]
Batch: Teacher:
BSEE 2024-28 Dr. Muhammad
Tufail
Semester Lab Engineer:
1st Mr. Adam Abbas
Mr. M Hunzilah
Ahmad
Department of Electrical Engineering
LAB TASK : 6

TASK:1

CODE:
#include<iostream
>
#include<iomanip>
using namespace
std; int main() {
int a, b;
cout << "Enter your first number : " <<
endl; cin >> a;
cout << "Enter your second number : " <<
endl; cin >> b;
int max,
min; int sum
= 0; if (a >
b) {
max =
a; min
= b;
}
else {
max =
b; min
= a;
}
for (int i = min; i < max; i++)
{
if (i % 2 == 0)
{
cout << i <<
setw(10); sum =
sum + i;
}
}
cout << "sum of even numbers are : " << sum;
}

OUTPUT:

TASK:2
CODE:
#include<iostream>
using namespace
std; int main() {
int n;
cout << "Enter value of n : " <<
endl; cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
int partialsum = 0;
for (int j =1; j <= i; j++) {
partialsum = partialsum +
j;
}
sum += partialsum;
}
cout << sum << endl;

Output:

TASK:3

CODE:
#include<iostream>
using namespace
std; int main() {
int n;
cout << "Enter the value of vertical lines : " <<
endl; cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= i; j++)
{
cout <<
j; if (j
<i)
{
cout << " + ";
}
}
cout << endl;
}
}
OUTPUT:
TASK:4

CODE:
#include<iostream>
using namespace
std; int main() {
int n;
cout << "Enter the value of vertical lines : " <<
endl; cin >> n;
for (int i=0 ; i<=n ; i++)
{
for (int j = n;j>i; j--)
{
cout << j<<"\t";

}
cout << endl;
}
}

OUTPUT:

TASK:5
CODE :

#include<iostream>
using namespace
std; int main() {
int rows;
cout << "Enter number of rows " <<
endl; cin >> rows;
for (int i = 0; i < rows; i++)
{
for (int j = rows; j > i; j--)
{
cout << " ";
}
for (int k = 0; k <= i; k++)
{
cout << " * ";
}
cout << endl;
}
}
OUTPUT:

You might also like