Lab 6
Lab 6
Programming
CIS-101
Fall 2022
Lab Report no. 6
Obtained Marks
Total Marks
Student Name
RAYYAN QUDDUSI
Section:
Experiment No: 6 Date of Submission:
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: