Given an integer N, print a full pyramid of asterisks. A full pyramid of asterisks of size N has N l…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
@Mohammad.Ali Read the problem statement carefully. Your output is incorrect. You can test your output in udebug here and test what is wrong in your output.
The problem is, you are not printing the spaces between asterisks which is shown in the sample test cases. for example for the input
Normally when submissions for this kind of problems does not work, it is for a silly mistake. So, I thought it was something identical here.
I read your code in a hurry and mistook " *" with "*". And so, I thought that you forgot to put space in there.
I didn’t even bother to run your code like I do, usually.
However, I properly run your code here and tested the output it in uDebug. Here is what I got.
It seems to be that you are printing 2 unnecessary spaces in front of every single line.
It was something silly after all, you should have tested the output of your code in uDebug here. That’s probably the reason why you are getting a Wrong Answer.
Fix it and your code should be accepted.
And please don’t share screenshots of your code. If want to show the output, you can use ideone.
@corrupted_brain, at least try to read previous posts before posting your problem. You are printing an extra space at the end of every line, fix it and it will do.
Extra space at the end of every line.
You should read previous posts before you post @Aiden_Pirace.
You can find the answer to your question without even asking that way.
Cause people tend to do the same mistakes.
#include<stdio.h>
int main()
{
int i, j, k, n;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
for (j = 0; j < n - i; j++)
printf(" ");
for (k = 0; k <= i; k++)
{
printf("*");
if (k!=i)
printf(" ");
}
if (i!=n-1)
printf("\n");
}
return 0;
}