Hey, everyone~

Being the second time posting here, I'll try to make it simple but clearly as possible :)

So, my assignment this time is about writing a C program to print the following star patterns:

      *  *
   *  *  *
*  *  *  *

So, here is an answer that I found online:

/* This is a simple mirror-image of a right angle triangle */

int main() {
 char prnt = '*';
 int i, j, nos = 4, s;
 for (i = 1; i <= 5; i++) { for (s = nos; s >= 1; s--) {  // Spacing factor
   printf("  ");
  for (j = 1; j <= i; j++) {
   printf("%2c", prnt);
  --nos;   // Controls the spacing factor
 return 0;


The lecturer in my class hasn't taught us this type of coding yet.
So we're supposed to write a simpler program for it, with using only char variable and printf w/ scanf instructions. So, I tried doing it like this:

#include <stdio.h>
int main()
    char x = '*'
    printf("%4c", x\n);
    printf("%3c %4c", x x\n);
    printf("%2c %3c %4c", x x x\n);
    printf("%1c %2c %3c %4c", x x x x\n);
return 0;

BUT I found it to be COMPLETELY WRONG.....So, I want to write the program like the one I did above here CORRECTLY...not like the program I found up there. Get me? If you get what I mean, please help me out and correct the mistakes I did in the program I wrote above here (^_*)

Edited by UNDER-18 FG: n/a

6 Years
Discussion Span
Last Post by firstPerson
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.