0
Help me with this output. The output is shown below but not getting program how to do.
If user input n=2 then output show @ @**@ @**@ @ If user inputs n=4 then output will be @ @ @**** @ **** @ @ **** @ ****@ @ @ Help with me.
16 Answers
+ 3
put your code on code playground and link it here
+ 3
I think you missed a space in the first example. Here is a code making patterns:
https://code.sololearn.com/cw1aqUXI5Iaz/?ref=app
Edit: now the padding is exactly like in the question: no spaces in n=2 output.
+ 3
No problem Bro. Next time you can try following approach:
1. find relations between input and pattern parameters:
- number of lines (2n)
- starting character: @ if line<=n+1, otherwise " "
- ending character: @ if line>=n, otherwise " "
- number of characters in line n+(n-1)*n/2
- offsets
- padding
2. Make an outer loop for lines
3. Make inner loop(s) for characters in the line
Another approach is to make a string variable and modify it to print each line
+ 2
PRINCE KUMAR Check this updated by me
https://code.sololearn.com/czdTT7gzmRSC/?ref=app
+ 2
PRINCE KUMAR
You can place a mark on Victor's answer as a token of gratitude for his efforts working on the code, and his explanation clears how the pattern is formed.
+ 1
have you try writing some code for this, if(true) show it; else try write some, users here don't write code for others but help em fix it
+ 1
PRINCE KUMAR
I understand you need help with how to solve this. But I'm having difficulty also trying to understand the pattern (about the padding and missing @ character), as I have asked in my earlier response (please see it).
Until I'm seeing clearly how the pattern works, I'm afraid I can't suggest you anything (sorry).
+ 1
It is giving right answer bro
0
Yes I have written
# include<conio.h>
# include<conio.h>
void main()
{
int n,i,j,k=1,m;
clrscr();
printf("enter no.");
scanf("%d",&n);
for(i=1; i<=n+1; i++)
{
for(m=i; m<=i; m++)
{
printf("@");
}
for(j=1; j<k; j++)
{
printf(" ");
}
for(j=1; j<=n; j++)
{
printf("*");
}
printf("\n");
k=k+(n-1);
}
getch();
}
0
✳AsterisK✳
Here is a code
https://code.sololearn.com/cF5wG61Xf8qK/?ref=app
0
I'm not understanding the pattern, when N = 2, the asterisks are printed without any padding.
@**@ // no padding whatsoever
@**@
But when N = 4, there's a padding to the left and/or right side of the asterisks. Shouldn't there also be a padding for the case N = 2?
@****
@ **** @ // left/right padding
@ **** @ // left/right padding
****@ // left padding
And there's a missing '@' to the left and to the right for the case N = 4
@**** // missing right @
@ **** @
@ **** @
****@ // missing left @
(Edited)
0
The output is correct but not getting how to built program
0
Ipang see question above
0
In case of n=2 When n=2 executes then @ runs 1 more means it prints @ three times
And also Asterisk 3 times but with padding.
Yes there is a padding on right as well as left also
And in case of n=4
The output is correct.
and also Asterisk start printing from middle of @
0
✳AsterisK✳ help me bro
0
Victor thanks bro