Hi there,
I am a beginner to C++. I have been trying to write the codes for approximately a month. Now I am studying Loops. I have come across many programs printing a certain pattern with the help of loops. Here is a program written by me;
Now, I have tried to get the same output but in a pyramid form, I have tried a lot but I can't make any logic. I know some of it like
I want the output of the first program to appear in a form of a pyramid. I tried to code it (as i showed you in the second code) but it is not giving me the required output. I hope you can give me some hints to help solve this issue. Thanks.
I am a beginner to C++. I have been trying to write the codes for approximately a month. Now I am studying Loops. I have come across many programs printing a certain pattern with the help of loops. Here is a program written by me;
#include <iostream> #include <conio.h> using namespace std; void main() { int number; int temp; cout << "Enter a number: "; cin >> number; temp = number; for (int i = 1; i <= number; i++) { for (int j = 1; j<=temp; j++) cout << j; temp--; cout << endl; } getch(); }
Now, I have tried to get the same output but in a pyramid form, I have tried a lot but I can't make any logic. I know some of it like
#include <iostream> #include <conio.h> using namespace std; void main() { int number, temp; cout << "Enter a number: "; cin >> number; temp = number; for (int i = 1; i<=number; i++) { for (int j = 1; j<=i; j++) cout << " "; for (int k = 1; k<=2*i-1; k++) cout << k; cout << endl; } getch(); }
I want the output of the first program to appear in a form of a pyramid. I tried to code it (as i showed you in the second code) but it is not giving me the required output. I hope you can give me some hints to help solve this issue. Thanks.