Need help in printing a pattern

I need help in printing a pattern. i am able to print some of it but some part is giving me tough time.
pattern is like

is this your homework?:stuck_out_tongue:

2 Likes
n=int(input())
for i in range(1, n+1):
    e = ' '*(2*(n-i))
    nums = [str(i)]*i
    nums = ' * '.join(nums)
    print(e+nums)
1 Like

I won my first contest in school by solving this. :sweat_smile::sweat_smile:

1 Like

//pattern of doubt
import java.util.Scanner;
public class Doubt
{
private int ln;
public void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println(" ENTER LINE NUMBER “);
ln=sc.nextInt();
int lt=1;
for(int i=1;i<=ln;i++)
{
for(int j=ln; j>i;j–)
System.out.print(” “);
for(int k=1;k<=lt;k++)
{
if((k%2)==0)
System.out.print(”*");
else
System.out.print(i);
}
lt+=2;
System.out.println();
}
}
}

here’s the working code in java. Hope this is not your homework! :wink:

https://ideone.com/oB2pBi
C - lang.
At early stage i used to find these questions alot difficult:smile:

1 Like

i don’t have knowledge of java yet. can u make this in c or c++

can u print this same in c language please

1 Like

If you can print the star pyramid then just do this print first loop’s variable’s value at every odd indices.
:slight_smile:

num = int(input())
for x in range(1,num+1):
print(" “(num-x),end= “”)
for y in range(x-1):
print(str(x)+’
’,end=”")
print(x)