create code for shapes in C

Hello all, I'm new to this website, and I am also new to coding. I am having trouble creating a program to create shapes based on the type of width selected by me (of an odd number no less than 5, no greater than 23). I am working on visualstudio. The constraints are listed below. 1. For each shape you create via your code, you may only use an escape character sequence (e.g. “\n, \t”) up to 3 times. 2. For each shape you create via your code, you may only use the printf function up to 3 times. These constraints are forcing you to find a combination of selection and conditional loops structures that will generate the shape. A shape that I would need help on making would be like a diamond (essentially one regular triangle and upside triangle to create a diamond) but I cannot figure it out.

Any help would be greatly appreciated!:) I hope to be amazing at code like you guys are one day!

Answers

  • Maybe you should be more clear about why and for what you want to do this? Why does it has to be in C? Homework?

    Since this forum is about Processing (Java), it might not be the best place to look for help regarding C and Visual Studio.

    I could show you an example how this could be done in Processing, maybe that helps as a starting point and you can translate that to C.

    void setup() {
      // desired width
      int w = 25;
    
      // rows
      for (int row = 0; row<w*2; row++) {
        // string to store characters
        String line = "";
        // columns
        for (int col =0; col<w; col++) {
          if(col < abs(row-w) || col >= w-abs(row-w) )
            line += " ";
          else
            line += "*";
        }
          println(line);
      }
    }
    
  • oh, i'm sorry I was not aware this was only for java. Thank you for the example. I don't know how to translate it. but I really appreciate your help.

  • Do you atleast know what Processing is?

Sign In or Register to comment.