In general, building a pyramid by code is not very easy. But I made it by writing only three line codes😁. But I do not understand why my code is not acceptable. What is the problem in my code?.However why my stars are not showing up(one asterisk after print(" "* and one inside of )+“*”)
Python 3
n = int(input())
for i in range(n):
print(" "*(n-(1+i))+"* "*(1+i))
Scanner input=new Scanner(System.in);
int N;
N=input.nextInt();
for (int r =1; r<=N; r++)
{
for (int c = 1; c <=N-r; c++){
System.out.print(" ");
}
for (int c =1; c <=r; c++) {
System.out.print(" *");
}
System.out.println();
}
What’s the problem in my code ???
#include<stdio.h>
int main()
{
int i,j,a,b,c,d,y,z,m;
char ara[100][200];
char x;
x = '';
for(i=0; i<100; i++) {
for(j=0; j<200; j++) {
ara[i][j] = ’ ';
}
}
scanf(“%d”,&a);
c = 0;
d = 0;
y = a;
z = (2a) -1;
m = a-1;
for(i=0; i < y ; i++) {
b = i + 1;
d = m;
for(j=0; j < z; j++) {
if(j==m||j==d) {
if(c<b) {
ara[i][j]=x;
c++;
d = d +2;
}
}
}
m--;
c=0;
}
for(i=0; i < y ; i++){
for(j=0; j < z; j++){
printf("%c",ara[i][j]);}
printf("\n");
}
return 0;
number=int(input())
var=1
number_space=number
sign=“*”
val=0
while var<=number:
string=“”
if val==0:
for i in range(1,number_space):
string+=" "
string=string+sign
val=1
var+=1
number_space-=1
print(string)
else:
var+=1
for i in range(1,number_space):
string+=" "
for i in range(1,var):
if val!=number:
string+=(sign+" ")
else:
string=string+sign
number_space-=1
print(string)
Can anyone say what’s wrong with this code? Preformatted text // C++ code to demonstrate star pattern
`#include
using namespace std;
// Function to demonstrate printing pattern
void triangle(int n)
{
// number of spaces
int k = 2 * n - 2;
// Outer loop to handle number of rows
// n in this case
for (int i = 0; i < n; i++) {
// Inner loop to handle number spaces
// values changing acc. to requirement
for (int j = 0; j < k; j++)
cout << " ";
// Decrementing k after each loop
k = k - 1;
// Inner loop to handle number of columns
// values changing acc. to outer loop
for (int j = 0; j <= i; j++) {
// Printing stars
cout << "* ";
}
// Ending line after each row
cout << endl;
}
@abir123 Let’s say for the first line, you want to print 5 spaces and then an asterisk. Instead of printing something like xxxxx* (where the xs are spaces), you are printing xxxxx*x. Notice what’s wrong?
I am totally stuck, @hjr265, please give me a suggestion…
#Full Pyramid
n = int(input())
for i in range(0, n + 1):
for k in range(1, n +1 - i):
print(" ", end="")
for j in range(1, i + 1):
print("*", end=" ")
print()