Skip to content

Commit aecd400

Browse files
committed
added test 1 programs
1 parent 2d826a8 commit aecd400

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ This repo includes:
3737
- [Decimal to binary](./milestone1/operatorsandforloop/DecimaltoBinary.cpp)
3838
- [Square Root (Integral)](./milestone1/operatorsandforloop/SquareRoot(Integral).cpp)
3939
- [Check Number sequence](./milestone1/operatorsandforloop/CheckNumbersequence.cpp)
40+
- [Test 1](./milestone2/test1/)
41+
- [Pyramid Number Pattern](./milestone2/test1/PyramidNumberPattern.cpp)
42+
- [Number Star Pattern](./milestone2/test1/NumberStarPattern.cpp)
43+
- [Second Largest](./milestone2/test1/SecondLargest.cpp)
4044

4145
# Coding Ninjas
4246
## Rate my Repo ⭐!!!
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Print the following pattern for given number of rows.
2+
// Input format :
3+
4+
// Line 1 : N (Total number of rows)
5+
6+
// Sample Input :
7+
// 5
8+
// Sample Output :
9+
// 1234554321
10+
// 1234**4321
11+
// 123****321
12+
// 12******21
13+
// 1********1
14+
15+
#include<iostream>
16+
using namespace std;
17+
18+
int main(){
19+
int n;
20+
cin>>n;
21+
int i = 1;
22+
while (i <= n){
23+
int j = 1;
24+
while (j <= n-i+1){
25+
cout<<j;
26+
j++;
27+
}
28+
int sp = 1;
29+
while (sp <= 2*(i-1)){
30+
cout<<"*";
31+
sp++;
32+
}
33+
int k = n-i+1;
34+
while (k >= 1){
35+
cout<<k;
36+
k--;
37+
}
38+
cout<<endl;
39+
i++;
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Print the following pattern for the given number of rows.
2+
// Pattern for N = 4
3+
// 1
4+
// 212
5+
// 32123
6+
// 4321234
7+
// Input format : N (Total no. of rows)
8+
9+
// Output format : Pattern in N lines
10+
11+
#include <iostream>
12+
using namespace std;
13+
14+
int main() {
15+
int n;
16+
cin>>n;
17+
int i=1;
18+
while (i <= n){
19+
int sp=1;
20+
while (sp <= n-i){
21+
cout<<" ";
22+
sp++;
23+
}
24+
int j=1;
25+
int k=i;
26+
while (j <= i){
27+
cout<<k;
28+
k--;
29+
j++;
30+
}
31+
int l = 2;
32+
while (l <= i){
33+
cout<<l;
34+
l++;
35+
}
36+
cout<<endl;
37+
i++;
38+
}
39+
}

milestone2/test1/SecondLargest.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Take input a stream of n integer elements, find the second largest element present.
2+
// The given elements can contain duplicate elements as well. If only 0 or 1 element is given, the second largest should be INT_MIN ( - 2^31 ).
3+
// Input format :
4+
5+
// Line 1 : Total number of elements (n)
6+
7+
// Line 2 : N elements (separated by space)
8+
9+
// Sample Input 1:
10+
// 4
11+
// 3 9 0 9
12+
// Sample Output 1:
13+
// 3
14+
15+
#include<iostream>
16+
using namespace std;
17+
#include <climits>
18+
19+
int main() {
20+
int n;
21+
cin >> n;
22+
int max = INT_MIN, secondMax = INT_MIN;
23+
int num;
24+
int count = 1;
25+
while(count <= n) {
26+
cin >> num;
27+
if(num > max) {
28+
secondMax = max;
29+
max = num;
30+
}
31+
else if(num > secondMax && num != max) {
32+
secondMax = num;
33+
}
34+
count++;
35+
}
36+
cout << secondMax << endl;
37+
}

0 commit comments

Comments
 (0)