Click here to Skip to main content
16,018,006 members
Please Sign up or sign in to vote.
1.80/5 (4 votes)
See more:
Guys, I want to print asterisk in W shape. I can't seem to figure it out. Been looking for it all over Google as well. Need help, please. The code has to be in C language. (I'm relatively new to programming)

*         *

*         *

*    *    *

*  *   *  *

*         *



Update: (It's not displaying the shape correctly here)

[edit]Code block added (it's displaying the shape properly now) - OriginalGriff[/edit]
Posted
Updated 24-Oct-13 9:37am
v5
Comments
OriginalGriff 24-Oct-13 15:11pm    
Shape fixed (I added a code block for you - use the "Improve question" widget to have a look)

What have you tried? Where are you stuck?
ZurdoDev 24-Oct-13 16:18pm    
What's your question?

It is very easy to write using standard function printf
C++
int printf ( const char * format, ... );

Print formatted data to stdout
Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.
C++
#include <stdio.h>

int main()
{

    printf("*         *\n");
    printf("           \n");
    printf("*         *\n");
    printf("           \n");
    printf("*    *    *\n");
    printf("           \n");
    printf("*  *   *  *\n");
    printf("           \n");
    printf("*         *\n");

    return 0;
}

Regards,
Alex
 
Share this answer
 
Since it's C, you should use
C++
printf("theline\n");
for each line.

So, that's how it should finally look:

C++
#include<stdio.h>
#include<conio.h>

int main(){
  printf("*       *\n");
  printf("*       *\n");
  printf("*   *   *\n");
  printf("* *   * *\n");
  printf("*       *\n");
  getch(); //if you don't use some input function, the program will exit without letting you see the tesult
  return 0;
}
 
Share this answer
 
v2
Comments
StoyanovZ 26-Oct-13 7:56am    
I didn't see that someone has already answered :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900