Given an integer number N as input. Write a program to print the double triangular pattern of N lines using an asterisk(*) character as shown below.
write c++ statements to declare an integer variable score and a double constant TARGET. initialize them with 15 and 20.0 respectively?
L=int(input())
count=0
for a in range(1,L-1):
for b in range(a+1,L):
for c in range(b+1,L+1):
x=a*a
y=b*b
z=c*c
if (x+y==z):
count+=1
print(count)
What is the trick behind this problem
Given a string, an integer position, and a character, all on separate lines, find the character of the string in that position and replace it with the character read. Then, output the result.
Ex: If the input is:
warn
e
the output is:
earn
Note: Using a pre-defined string function, the solution can be just one line of code.
#include <iostream>
#include <string>
using namespace std;
int main() {
string stringVal;
int stringPos;
char substituteChar;
getline(cin, stringVal);
cin >> stringPos;
cin >> substituteChar;
cout << stringVal << endl;
return 0;
}
Maximum
You are given N number of inputs. Print the maximum of them after each input.
Input
The first line of input is an integer N. The next N lines each contain an integer as input.
Explanation
In the example, you are given
6 inputs 1, 0, 3, 2, 9, 8.
1 is maximum in the input 1.
1 is maximum in the input 1, 0.
3 is maximum in the input 1, 0, 3.
3 is maximum in the input 1, 0, 3, 2.
9 is maximum in the input 1, 0, 3, 2, 9.
9 is maximum in the input 1, 0, 3, 2, 9, 8.
So, the output should be
1
3
3
9
9
Sample Input 1
6
1
3
2
9
8
Sample Output 1
1
1
3
3
9
9
Sample Input 2
5
1
2
3
4
5
Sample Output 2
1
2
3
4
5
Hollow Rectangle - 2
Write a program to print a rectangle pattern of M rows and N columns using the characters as shown below.
The first line of input is an integer M. The second line of input is an integer N.
In the given example, 3 rows and 10 columns.
Therefore, the output should be
+----------+
| |
| |
| |
+----------+
Sample Input 1
3
10
Sample Output 1
+----------+
| |
| |
| |
+----------+
Sample Input 2
5
10
Sample Output 2
+----------+
| |
| |
| |
| |
| |
+----------+