2 - PDS - LabAssignment - 2 - Sub Format
2 - PDS - LabAssignment - 2 - Sub Format
2 - PDS - LabAssignment - 2 - Sub Format
int main() {
int num, firstbig, secondbig, n, i = 0;
if (n < 2) {
cout << "At least two numbers are required." << endl;
return 1;
}
1. while (i < n) {
cout << "Enter number: ";
cin >> num;
i++;
}
cout << "The first biggest number is: " << firstbig << endl;
cout << "The second biggest number is: " << secondbig << endl;
return 0;
}
1
You are designing a program for an airport system. You must input each passenger's
arrival and departure times in the format hour: minute: second (24 hrs format). Your
program should calculate the waiting time for each person in the same format.
Additionally, you should calculate the cost incurred for this waiting time. For every 10-
minute interval, it is ₹100/-. Write a program to accomplish this task.
Example: Input
Output
Waiting time = 1:54: 52
Cost incurred is 1200 Rupees
2
#include <iostream>
using namespace std;
int main() {
int ah, am, as;
int dh, dm, ds;
int ta, td, tt;
int wh, wm, ws;
int cost;
ta = ah * 3600 + am * 60 + as;
td = dh * 3600 + dm * 60 + ds;
wh = tt / 3600;
tt %= 3600;
wm = tt / 60;
ws = tt % 60;
cout << "Waiting time = " << wh << ":" << wm << ":" << ws << endl;
return 0;
}
3
#include <iostream>
using namespace std;
int main() {
int N;
cout << "Enter the number of batches: ";
cin >> N;
int cumulativecount = 0,temp=1;
int i = 1;
while (i <= N) {
int numStudents;
cout << "Enter the number of students in batch " << i << ": ";
cin >> numStudents;
int j = 1;
cumulativecount++;
cumulativecount=temp;
while (j <= numStudents) {
temp++;
cout << cumulativecount << "." << j << endl;
j++;
}
i++;
}
return 0;
}
Write a C++ program to display the leap years that contain the digit ‘x’ given by the user,
between two given year n1 and n2 both inclusive. For example, if n1 and n2 are 1990 and
4 2020 and if the digit ‘x’ is 6, the outputs need to be: The number of leap years between
1990 and 2020 that contains the digit 6 are: 1996, 2016.
4
#include<iostream>
using namespace std;
int main() {
int n1, n2, x;
cout << "Enter the initial year: ";
cin >> n1;
cout << "Enter the final year: ";
cin >> n2;
cout << "Enter the digit you want to be included in the years: ";
cin >> x;
cout << "The leap years between " << n1 << " and " << n2 << " that contain the digit " << x << " are:" <<
endl;
return 0;
}
5
Consider that you are given a task of telling the berth position (lower/middle/upper/side
lower/side upper) based on the berth number in a railway coach. If the passenger is not
aware of his/her berth position, he/she shall approach you and you need to tell them the
same. Now imagine that you are in-charge for ‘n’ coaches. The following are your tasks:
i. Display the birth position according to the berth number told by the passenger.
ii. Display the total number of requests received from each coach’s passengers as
well as the total ‘n’ coaches.
Write a program to automate the above scenario.
A model coach with berth numbers is shown in Figure 1. Table 1 gives the respective
berth positions (continue the numbering till 72). Note that the capacity of a coach is for
72 passengers.
4: Lower
5: Middle
5 6: Upper
7: Side Lower
8: Side Upper
Table-1: Berth positions for berth numbers 1 to8.
Example:
Enter the number of coaches: 2
Coach-1:
Passenger-1: Berth Number: 23-----> Informed his/her berth position as: Side Lower
Passenger-2: Berth Number: 45-----> Informed his/her berth position as: Middle Berth
Total number of requests received from coach-1 are: 2
Coach-2:
Passenger-1: Berth Number: 10-----> Informed his/her berth position as: Middle
Passenger-2: Berth Number: 4-----> Informed his/her berth position as: Lower
Passenger-3: Berth Number: 32-----> Informed his/her berth position as: Side Upper
Passenger-4: Berth Number: 6-----> Informed his/her berth position as: Upper
Total number of requests received from coach-2 are: 4
The total number of requests received for this train are: 6
6
#include <iostream>
using namespace std;
int main() {
int n, num_of_passengers, berth_num, i = 1, total_requests = 0;
while (i <= n) {
int requests = 0;
cout << "Coach-" << i << ":" << endl;
int j = 0;
while (j < num_of_passengers) {
cout << "Passenger-" << (j + 1) << ": Enter Berth Number: ";
cin >> berth_num;
switch (berth_position) {
case 1:
cout << "Informed his/her berth position as: Lower Berth" << endl;
break;
case 2:
cout << "Informed his/her berth position as: Middle Berth" << endl;
break;
case 3:
cout << "Informed his/her berth position as: Upper Berth" << endl;
break;
case 4:
cout << "Informed his/her berth position as: Side Lower Berth" << endl;
break;
case 5:
cout << "Informed his/her berth position as: Side Upper Berth" << endl;
break;
}
requests++;
j++;
}
cout << "Total number of requests received from coach-" << i << " are: " << requests << endl;
total_requests += requests;
i++;
}
7
cout << "The total number of requests received for this train are: " << total_requests << endl;
return 0;
}
Write a program to read a 6-digit number and display it in words. Also shift the given
number one positions towards right by placing the last digit as the first digit in the result
and display it also in words.
Input: 123456
Output:
6 The given number in words: Lakhs: 1, Thousands: 23, Hundreds: 4, Tens: 5 and Ones: 6.
The resulted number is: 612345
The resulted number in words: Lakhs: 6, Thousands: 12, Hundreds: 3, Tens: 4 and Ones:
5.
8
#include <iostream>
using namespace std;
int main() {
int number;
cout << "The resulted number is: " << shifted_number << endl;
return 0;
}
Write a program to display the 2nd biggest number in each of ‘n’ lists of numbers, where
each list contains ‘m’ numbers, m≥2.
Example:
9
#include <iostream>
using namespace std;
int main() {
int n, m, num;
int firstbig, secondbig;
int j = 0;
while (j < m) {
cout << "Enter number: ";
cin >> num;
j++;
}
if (secondbig == INT_MIN) {
cout << "There is no second biggest number in list " << i << "." << endl;
} else {
cout << "Second biggest number in list " << i << " is: " << secondbig << endl;
}
}
return 0;
}
Write a program to display the sum of first ‘n’ even numbers in Fibonacci series. For
8 example, if n=4, the result is 188.
10
#include<iostream>
using namespace std;
int main(){
int a=0,b=1,i,sum,count;
cout<<"Enter no. of element you want in series";
cin>>count;
while(i<=count){
sum=a+b;
a=b;
b=sum;
if(sum%2==0){
int en=sum;
cout<<en<<" ";
}
i++;
}
}
Write a program to print all the prime numbers between GCD and LCM of two user
defined integer numbers. If the given two integers are 20 and 14, the output needs to be
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
9 101, 103, 107, 109, 113, 127, 131, 137, 139.
11
#include <iostream>
#include <cmath>
int main() {
int n1, n2;
cout << "Enter two integers: ";
cin >> n1 >> n2;
cout << "Prime numbers between GCD (" << gcd << ") and LCM (" << lcm << "):" << endl;
int i = gcd;
while (i <= lcm) {
if (i >= 2) {
int prime = 1;
int j = 2;
while (j <= sqrt(i)) {
if (i % j == 0) {
prime = 0;
break;
}
j++;
}
if (prime == 1) {
cout << i << " ";
}
}
i++;
}
12
In India, when multiple couples show up at the marriage registration office at the same
time, they have trouble deciding which couple to marry first because they can only do one
wedding at a time. Dishant, who works in the marriage department along with Naman,
has a solution. They suggest a way to decide the order of marriages. They will compare
the age difference between the couples. The greater the age difference between a couple,
the higher their priority will be for getting married. Also print the date of marriage of each
couple
1. For First Couple Marriage (who is having maximum age difference) marriage date
is calculated by adding 15 days to current date (17-10-2023).
2. For the remaining couple marriage date is calculated by adding 30 days to current
date(17-10-2023).
Help Dishant and Naman in ordering the marriage of the two couples and displaying the
10 marriage day of each couple by writing a computer program for this. Note that all the 12
months contain 30 days each.
Example: Couple 1: Bride(Girl) date of birth: 15 5 2001
Groom (Boy) date of birth: 25 9 1997
Couple 2: Bride(Girl) date of birth: 25 6 2001
Groom (Boy) date of birth: 27 10 1997
Output
Age difference of Couple 1 = 03 Years 7 months 20 days
Age difference of Couple 2 = 03 Years 7 month 28 days
Couple 2 will get Married First
Marriage date for Couple 2 : 2 11 2023
Marriage date for Couple 1 :17 11 2023
13
#include <iostream>
using namespace std;
int main() {
int b1d, b1m, b1y;
int g1d, g1m, g1y;
int b2d, b2m, b2y;
int g2d, g2m, g2y;
if (ad1d < 0) {
ad1m--;
ad1d += 30;
}
if (ad1m < 0) {
ad1y--;
ad1m += 12;
}
if (ad2d < 0) {
ad2m--;
ad2d += 30;
}
if (ad2m < 0) {
ad2y--;
ad2m += 12;
}
cout << "Age difference of Couple 1 = " << ad1y << " Years "
<< ad1m << " months " << ad1d << " days" << endl;
cout << "Age difference of Couple 2 = " << ad2y << " Years "
<< ad2m << " months " << ad2d << " days" << endl;
14
cout << "Marriage date for Couple 2: " << b2d + 15 << " "
<< b2m << " " << b2y << endl;
cout << "Marriage date for Couple 1: " << b1d + 30 << " "
<< b1m << " " << b1y << endl;
}
return 0;
}
Our NIT Warangal offer n undergraduate programmes (CSE, Civil,...). Moreover, let us
assume that for each program, intake of students is m based on JEE mains rank. Write a
program to read the JEE mains rank of students in each branch and display the starting
rank and ending rank for each branch.
Example:
Enter the number of undergraduate programs in NITW: 3
Enter the number of students in program 1: 4
Enter the student 1 in program 1: 524
Enter the student 2 in program 1: 124
Enter the student 3 in program 1: 555
Enter the student 4 in program 1: 444
Starting rank and ending rank for program 1 is 124 and 555
11 Enter the number of students in program 2: 3
Enter the student 1 in program 2: 5524
Enter the student 2 in program 2: 5124
Enter the student 3 in program 2: 5444
Starting rank and ending rank for program 2 is 5124 and 5524
Enter the number of students in program 3: 5
Enter the student 1 in program 3: 5
Enter the student 2 in program 3: 9
Enter the student 3 in program 3: 1
Enter the student 4 in program 3: 7
Enter the student 5 in program 3: 6
Starting rank and ending rank for program 3 is 1 and 9
15
#include <iostream>
int main() {
int n;
cout << "Enter the number of undergraduate programs in NITW: ";
cin >> n;
int i = 1;
while (i <= n) {
int m;
cout << "Enter the number of students in program " << i << ": ";
cin >> m;
int rank;
cout << "Enter the student 1 in program " << i << ": ";
cin >> rank;
int j = 2;
while (j <= m) {
cout << "Enter the student " << j << " in program " << i << ": ";
cin >> rank;
cout << "Starting rank and ending rank for program " << i << " is " << minRank << " and " <<
maxRank << endl;
i++;
}
return 0;
}
16
There are ‘n’ farmers in a village. They cultivate paddy in their agriculture lands. They
all send their paddy to a miller. The miller said that 76kgs of paddy is considered as one
bag. Each farmer has given his paddy to the miller. Write a program to read the paddy of
each farmer and display the total number of bags and kgs of the paddy of that village.
Note that each farmer enters two integers: first one represents the bags and the second one
represents the number of kgs.
Example: Enter the number of farmers: 4
Enter the amount of paddy of farmer 1: 16 20 (i.e 16 bags 20 kgs)
Enter the amount of paddy of farmer 2: 12 42 (i.e 16 bags 20 kgs)
Enter the amount of paddy of farmer 3: 14 25 (i.e 16 bags 20 kgs)
Enter the amount of paddy of farmer 4: 16 0 (i.e 16 bags 20 kgs)
Output: The total number of paddy from this village is: 59 bags 11 kgs.
#include<iostream>
using namespace std;
int main(){
int bags,weight,nof,i=1;
cout<<"Enter the no. of farmers in village ";
cin>>nof;
while(i<=nof){
if(i==nof){
cout<<"Total weight in the village:"<<(sum/16)<<"Bags &"<<(sum%16)<<"kgs";
}
i++;
}
The cost price, mark price (MRP) and discount (in %) is entered through keyboard.
Sometimes seller gets profit of x % or some time loss of y % depends on discount. Write
a program to determine whether the seller has made profit or incurred loss. Also determine
13 how much profit he made or loss incurred.
17
#include<iostream>
using namespace std;
int main(){
double cost,MRP;
cout<<"Enter the cost price of product";
cin>>cost;
cout<<"Enter the MRP of product";
cin>>MRP;
if((MRP-cost)>0){
double profit=MRP-cost;
cout<<"Profit:"<<(profit/cost)*100<<"%";
}
else{
double loss=cost-MRP;
cout<<"Loss:"<<(loss/cost)*100<<"%";
}
if(cost==MRP){
cout<<"You sold it at Zero profit";
}
}
It is possible to calculate easily the day of the week on which a given date falls, if one
knows the Julian day of that date. For example, January 1 is always Julian day 1, since it
is the first day of the year, whereas December 31 is day 365 in a non-leap year or day 366
in a leap year. The day of the week is calculated as follows:
Year = year in question (all four digits)
Julian_day = Julian day of date in question (1 to 366)
fours = integer portion of (year -1)/4
hundreds = integer portion of (year-1)/100
14 four_hundreds = integer portion of (year-1)/400
day_of_the_week = (year + Julian_day + fours – hundreds + four_hundreds ) % 7 where:
Write a program to calculate the day of the week as described above. Verify its correctness
by testing it on the current date.
Note: Your program need to display only the number, it need not display the
corresponding day name.
18
#include <iostream>
using namespace std;
int main() {
int y, jd, f, h, fh, dow;
f = (y - 1) / 4;
h = (y - 1) / 100;
fh = (y - 1) / 400;
dow = (y + jd + f - h + fh) % 7;
cout << "The day of the week is: " << dow << endl;
return 0;
}
Write a program that plays the game of Mad Lib. Your program should prompt the user
to enter the following data.
After the data are input, they should be substituted into the story below and output to the
15 console.
----------------------------------------------------------------------------------------------------
Dear Instructor [Instructor Name],
I am sorry that I am unable to turn in my homework at this time. First I ate a rotten
[Food], which made me turn [Color] and extremely ill. I came down with a fever of
[Number 100-120]. Next, my [Adjective] pet [Animal] must have smelled the remains of
19
#include<iostream>
using namespace std;
int main(){
char in,f,c,n,adj,an,yn;
cout<<"Enter Your name,A food,A number between 100 and 120,An adjective,A color,An animal"<<endl;
cin>>in>>f>>c>>n>>adj>>an>>yn;
cout<<"Dear Instructor"<<in<<endl;
cout<<"I am sorry that I am unable to turn in my homework at this time. First I ate a rotten
\n"<<'f'<<"which made me turn"<<'c'<<"and extremely ill. I came down with a fever of\n"<<'n'<<".Next,
my"<<'adj'<<"pet"<<'an'<<"must have smelled the remains of<<”\n”<<the"<<'f'<<"on my homework,
because he ate it. I am currently rewriting my homework\nand hope you will accept it
later.\nSincerely,\n"<<'yn'<<endl;
}
Write a program to display the sum of alternate numbers in each of ‘n’ lists but also this
sum need to be calculated by starting alternate positions in alternate list as given in the
example. Here each list can contain ‘m’ numbers, m≥1.
20
#include <iostream>
using namespace std;
int main() {
int n, m, num, sum;
cout << "Enter the number of lists: ";
cin >> n;
int i = 1;
while (i <= n) {
cout << "Enter the number of elements in list " << i << ": ";
cin >> m;
sum = 0;
int j = 0;
while (j < m) {
cout << "Enter number: ";
cin >> num;
j++;
}
cout << "Sum of alternate numbers in list " << i << " is: " << sum << endl;
i++;}
return 0;
}
21
In our NIT Warangal, we have some courses which have both theory and Lab components.
A faculty may conduct theory for ‘x’ marks and Lab part for ‘y’ marks, where each of ‘x’
and ‘y’ may have ‘m’ and ‘n’ subparts respectively. The total of x and y can be >100 or <
100 or equal to 100. The weightage given to theory part is 75% and lab part is 25%. The
final marks for the student to be considered is out of 100. Assume that the values of all
exam’s marks of both ‘m’ and ‘n’ are known to you. Write a program to display the
percentage of contribution of all the ‘m’ and ‘n’ parts. Your program should work for
any valid values of x, y, m and n.
Example-1:
Enter the Total marks of theory part: x : 40
Enter the number of exams in theory part: m: 2
Enter the marks for each of ‘m’ exams: 10 30
Enter the Total marks of lab part : y: 20
22
#include <iostream>
using namespace std;
int main() {
int x, m, y, n;
cout << "Enter the total marks of theory part: ";
cin >> x;
int theory[m];
cout << "Enter the marks for each of " << m << " theory exams: ";
int theory_sum = 0;
int lab[n];
cout << "Enter the marks for each of " << n << " lab exams: ";
int lab_sum = 0;
return 0;
}
23
Given an integer N. Write a program to find the number in the range from 1 to N-1 which
is having the maximum number of terms in its Collatz Sequence and the number of terms
in the sequence. The Collatz Sequence is defined as: start with any positive integer n.
Then each term is obtained from the previous term as follows: if the previous term is even,
the next term is one half of the previous term. If the previous term is odd, the next term is
3 times the previous term plus 1. The conjecture is that no matter what value of n, the
18 sequence will always reach 1.
For example if N=13, Output: The Collatz Sequence is:
13 -> 40 -> 20 -> 10 -> 5 > 16 -> 8 -> 4 -> 2 -> 1
The number of terms are: 10
24
#include <iostream>
using namespace std;
int main() {
int n, max_terms = 0, number_with_max_terms = 0;
int i = 1;
while (i < n) {
int count = 0;
int current = i;
while (current != 1) {
if (current % 2 == 0) {
current /= 2;
} else {
current = 3 * current + 1;
}
count++;
}
i++;
}
cout << "The number with the maximum terms in its Collatz sequence is: "
<< number_with_max_terms << endl;
cout << "The number of terms are: " << max_terms + 1 << endl;
return 0;
}
Write a program that converts letters of the alphabets into their corresponding digits on
the telephone keypad as shown in the following diagram. The program should let the user
enter letters repeatedly until a ‘$’ symbol is entered by user. An error message should be
19 printed for any non-alphabetic character that is entered. Example, if the input is ‘M’, then
the corresponding digit is 6.
25
#include <iostream>
using namespace std;
int main() {
char input;
return 0;
}
Write a program to find the second largest number among n numbers entered. Example:
20 Input: 840, 288, 261, 337, 335, 488 Output: 488.
26
#include <iostream>
using namespace std;
int main() {
int n, num;
int firstbig = INT_MIN, secondbig = INT_MIN;
if (n < 2) {
cout << "At least two numbers are required." << endl;
return 1;
}
int count = 0;
count++;
}
if (secondbig == INT_MIN) {
cout << "There is no second largest number." << endl;
} else {
cout << "The second largest number is: " << secondbig << endl;
}
return 0;
}
27
The “Russian Peasant Problem” is a method multiplying two numbers together, using only
division by 2, multiplication by 2, and addition. For example, if the numbers 17 and 19
are to be multiplied together, they are put at the head of two columns. The first number,
17 is divided by 2 (using integer division), and the result is placed below the original
number in the first column. The second number, 19 is multiplied by 2; This process is
continued until the number on the left reduces to 1. All these numbers in the right hand
column which lie to the right of even numbers in the left hand column are ignored. The
remaining numbers in the right hand column then are added together (19+304=323). The
result is the solution to the problem, 17 time 19. Write a program to implement the Russian
Peasant method for multiplying any tow positive integers.
17 19
8 38 (ignore)
4 76(ignore)
2 152(ignore)
1 304
The result is : 323.
#include <iostream>
using namespace std;
int main() {
int a, b, result = 0;
21 while (a > 0) {
if (a % 2 == 1) {
result += b;
}
a /= 2;
b *= 2;
}
cout << "The result is: " << result << endl;
return 0;
}
28
#include <iostream>
using namespace std;
int main() {
int n, digit, count = 0;
int temp = n;
cout << "The occurrence of " << digit << " in " << n << " is: " << count << endl;
return 0;
}
Write a program to convert a decimal number to a binary number and count length and
number of 1s and number of 0s in the binary number.
For Example, if n=12
Binary Number is 1100
23 Length is 4
No. of 1s is 2
No. of 0s is 2
29
#include <iostream>
using namespace std;
int main() {
int n, binary = 0, count = 0, ones = 0, zeros = 0;
cout << "Enter a decimal number: ";
cin >> n;
int temp = n;
int place = 1;
cout << "Binary Number is: " << binary << endl;
cout << "Length is: " << count << endl;
cout << "No. of 1s is: " << ones << endl;
cout << "No. of 0s is: " << zeros << endl;
return 0;
}
*
*A*
*A*A*
24 *A*A*A*
*A*A*A*A*
30
#include <iostream>
using namespace std;
int main() {
int n = 5;
int i = 1;
while (i <= n) {
cout << "* ";
int j = 1;
while (j < i) {
cout << "A * ";
j++;
}
cout << endl;
i++;
}
return 0;
}
1
32
456
25 10 9 8 7
11 12 13 14 15
31
#include <iostream>
using namespace std;
int main() {
int n = 5;
int num = 1;
int i = 1;
while (i <= n) {
if (i % 2 != 0) {
int j = num;
while (j < num + i) {
cout << j << " ";
j++;
}
} else {
int j = num + i - 1;
while (j >= num) {
cout << j << " ";
j--;
}
}
num += i;
cout << endl;
i++;
}
return 0;
}
1
2*2
3*3*3
26 3*3*3
2*2
1
32
#include <iostream>
using namespace std;
int main() {
int n = 5; // You can change n to adjust the size of the pattern
int i = 1;
while (i <= n) {
int j = 1;
while (j <= i) {
cout << i << " ";
j++;
}
return 0;
}
**
**
*
27 **
**
33
#include <iostream>
using namespace std;
int main() {
int n = 5; // You can change n to adjust the size of the pattern
int i = 1;
while (i <= n) {
int j = 1;
while (j <= n - i) {
cout << " ";
j++;
}
j = 1;
while (j <= (2 * i - 1)) {
cout << "*";
j++;
}
return 0;
}
12
12
1
28 21
21
34
#include <iostream>
using namespace std;
int main() {
int n = 5; // You can change n to adjust the size of the diamond
int i = 1;
while (i <= n) {
int j = 1;
while (j <= n - i) {
cout << " ";
j++;
}
j = 1;
while (j <= (2 * i - 1)) {
cout << "*";
j++;
}
i = n - 1;
while (i >= 1) {
int j = 1;
while (j <= n - i) {
cout << " ";
j++;
}
j = 1;
while (j <= (2 * i - 1)) {
cout << "*";
j++;
}
return 0;
}
35
*****
**
*
**
*****
#include <iostream>
using namespace std;
int main() {
int n = 5; // You can change n to adjust the size of the pattern
int i = 1;
while (i <= n) {
int j = 1;
while (j <= i) {
29 cout << j << " ";
j++;
}
int k = i - 1;
while (k > 0) {
cout << k << " ";
k--;
}
return 0;
}
36
*****
*
*
*
*****
#include <iostream>
using namespace std;
int main() {
int n = 5; // You can change n to adjust the size of the pattern
int i = 1;
while (i <= n) {
int j = 1;
while (j <= n - i) {
cout << " ";
j++;
}
j = 1;
while (j <= (2 * i - 1)) {
30 cout << "*";
j++;
}
return 0;
}
37
1
2
3
4
5
5
4
3
2
1
1
2
3
4
4
3
2
1
1
2
3
3
2
1
1
2
2
1
31
1
1
#include <iostream>
using namespace std;
int main() {
int n = 5; // You can change n to adjust the size of the pattern
int i = 1;
while (i <= n) {
int j = 1;
while (j <= i) {
cout << j << " ";
j++;
}
int k = i - 1;
while (k > 0) {
cout << k << " ";
k--;
}
return 0;
}
38
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
39
#include <iostream>
using namespace std;
int main() {
int n = 6; // Number of rows
char c = 'A'; // Starting character
int i = 1;
while (i <= n) {
int j = 1;
while (j <= i) {
cout << c << " ";
j++;
}
return 0;
}
40
1
1
2
2
1
1
2
3
3
2
1
1
2
3
4
4
3
2
1
1
2
3
4
5
33 5
4
3
2
1
1
2
3
4
4
3
2
1
1
2
3
3
2
1
1
2
2
1
41
#include <iostream>
using namespace std;
int main() {
int n = 5; // Number of rows
int i = 1;
while (i <= n) {
int j = 1;
while (j <= i) {
cout << i << " ";
j++;
}
return 0;
}
42