Exp-5_N075
Exp-5_N075
Experiment: 5
PART B
Students must execute all the programs, write executed code in the workbook, and submit
part B of experiment 5 on the student portal. The filename should be
PPS_batch_rollno_experimentno. Example: PPS_A1_A001_P5
Tasks:
Write programs to print the following patterns using nested loop, your all program should
read number of lines to be displayed from user.
Sr. No. Pattern To Be Printed Using Nested Loop Flow chart
1
*****
****
***
** √
*
2 ????*
???**
??***
?****
*****
3 @
@ @
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
@ @ @
4 A
A B
A B C
C B A
B A
A
5 A
bc
DEF
ghij
KLMNO
6 54321
4321
321
21
1
7 1
10
101
1010
10101
8. Write a program to check entered number is strong number or not.
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
1. *****
****
***
**
*
Executed Code: -
/*Pattern To Be Printed Using Nested Loop
*****
****
***
**
**/
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 5; i>=0; i--) {
for (j = 0; j <= i; j++) {
cout << "*";
}
cout << endl;
}
return 0;
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
Input Output: -
2. ????*
???**
??***
?****
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
*****
Executed Code: -
/*Pattern To Be Printed Using Nested Loop
????*
???**
??***
?****
*****
*/
#include <iostream>
using namespace std;
int main() {
int i, j,k;
for (i = 5; i>=0; i--) {
for (j = 0; j <= i; j++) {
cout<<"?";
}
for (k = 5; k>=i; k--){
cout<<"*";
}
cout<<endl;
}
return 0;
}
Input Output: -
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
3. @
@ @
@ @ @
Executed Code: -
#include <iostream>
using namespace std;
int main() {
int i, j, k;
for (i = 0; i < 3; i++) {
for (k = 3; k > i; k--) {
cout << " ";
}
for (j = 0; j <= i; j++) {
cout << "@ ";
}
cout << endl;
}
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
return 0;
}
Input Output: -
4. A
A B
A B C
C B A
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
B A
A
Executed Code: -
#include <iostream>
using namespace std;
int main() {
int i, j, k;
for (i = 0; i < 3; i++) {
for (j = 0; j <= i; j++) {
k = 65 + j;
cout << char(k) << " ";
}
cout << endl;
}
for (i = 2; i >= 0; i--) {
for (j = 0; j <= i; j++) {
k = 65 + j;
cout << char(k) << " ";
}
cout << endl;
}
return 0;
}
Input Output: -
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
5. A
bc
DEF
ghij
KLMNO
Executed Code: -
#include <iostream>
using namespace std;
int main() {
int i, j;
char ch;
for (i = 1; i <= 5; i++) {
if (i % 2 == 1) {
ch = 'A' + (i * (i - 1)) / 2;
for (j = 1; j <= i; j++) {
cout << char(ch);
ch++;
}
} else {
ch = 'a' + (i * (i - 1)) / 2;
for (j = 1; j <= i; j++) {
cout << char(ch);
ch++;
}
}
cout << endl;
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
}
return 0;
}
Input Output: -
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
6. 54321
4321
321
21
1
Executed Code: -
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 5; i > 0; i--) {
for (j = i; j > 0; j--) {
cout << j;
}
cout << endl;
}
return 0;
}
Input Output: -
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
7. 1
10
101
1010
10101
Executed Code: -
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 1; i <= 5; i++) {
for (j = 1; j <= i; j++) {
cout << (j % 2);
}
cout << endl;
}
return 0;
}
Input Output: -
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
if (sum == num) {
cout << num << " is a Strong Number." << endl;
} else {
cout << num << " is not a Strong Number." << endl;
}
return 0;
}
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
Input Output: -
Additional Questions
1. Write a program to print tables from 1 to 10
for (i=1;i<11;i++){
for (j=1;j<11;j++){
cout<<"product of "<<i<<" and " <<j <<"="<<i*j<<endl;
}
cout<<endl;
}
return 0;
}
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
for (i=1;i<4;i++){
for (j=1;j<4;j++){
cout<<i<<j<<endl;
}
cout<<endl;
}
return 0;
}
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering / School of
Technology Management & Engineering
3. Write a C++ program to print Armstrong numbers between N1 to N2, where N2>N1.
4. Write a C++ program to print prime numbers between N1 to N2, where N2>N1.
5. Write a program in C++ to calculate the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... +
(1+2+3+4+...+n).