hey guys lol to be honest...i just got this based off of luck x.x
idk how but i can't keep doing this with the rest of my programs lol
this is a program for an asterick pattern

any way i can improve it just by using for loops?please im open for suggestions :)

- 3 spaces then an asterick, spaces decrement and increment and asterick increases by 2 then decrements by 2

int main()
  {
   int c,c_1,c_2,c_3,c_4,c_5,c_6;
       for(c=1;c<=3;c++)
          {
            for(c_1=3;c_1>=c;c_1--)
              printf(" ");
                 for(c_2=1;c_2<=(c_1+c+c+c_1);c_2+=2)
                    printf("*");
                    printf("\n");
          }
                     for(c_3=1;c_3<=7;c_3++)
                       {
                        printf("*");
                       }
                        printf("\n");
                       for(c_4=1;c_4<=3;c_4++)
                         {
                          for(c_5=1;c_5<=c_4;c_5++)
                           printf(" ");
                             for(c_6=14;c_6>=(c_4+c_5+c_4+c_5);c_6-=2)
                               printf("*");
                               printf("\n");
                         }
    return 0;
  }

Output on Codeblocks by mingw

*
  ***
 *****
*******
 *****
  ***
   *

First and foremost, learn to format your code. It's terrible and unreadable.

Second, asking for help using lol, idk, XD, and x.x gives us no information other than you spend too much time talking to the computer and not with real people. These are unnecessary and annoying computer geek jargon.

Third, you obviously didn't sit at a desk with pencil and paper to analyze the task to be accomplished. The more you understand the task, the easier to program it is. That means if it takes you 6 hours to program something start to finish,
a) the first 3-1/2 hours is at a desk understanding the task and planning the code,
b) 30 minutes programming the code,
c) 2 hours running and debugging to make the code perfect.

I remember one programming task I had I spent 4 hours understanding and planning the code, 15 minutes typing to code in, and 2 minutes fixing the one and only error - a typo. Any guess how long it would have taken if I sat down at the computer and just started programming?

First and foremost, learn to format your code. It's terrible and unreadable.

Second, asking for help using lol, idk, XD, and x.x gives us no information other than you spend too much time talking to the computer and not with real people. These are unnecessary and annoying computer geek jargon.

Third, you obviously didn't sit at a desk with pencil and paper to analyze the task to be accomplished. The more you understand the task, the easier to program it is. That means if it takes you 6 hours to program something start to finish,
a) the first 3-1/2 hours is at a desk understanding the task and planning the code,
b) 30 minutes programming the code,
c) 2 hours running and debugging to make the code perfect.

I remember one programming task I had I spent 4 hours understanding and planning the code, 15 minutes typing to code in, and 2 minutes fixing the one and only error - a typo. Any guess how long it would have taken if I sat down at the computer and just started programming?

well to be honest , plain and out just 1 word...thank you :)
unfortunately i did not do all of that, i just went and did this under an hour, i understood everything as i typed it ...it is just that i did this along with 2 projects so the only problem is the for loop ..but that itself is no excuse.

Thank you that post made a big difference

commented: and this post makes this 'job' worthwhile. Thank you. +17
commented: This post was a breath of fresh air. You made my day by being so understanding. :) +17

You only need two for loops, one nested inside the other.

The outer for loops handles how many rows, and the inner for loop handles the printing on that row.

for(r = ....etc ) {
   for(c = ....etc ) {
      with every loop you'll either add or subtract one or two to the r
      variable, which is quite nice, because it relates closely with how many 
      stars to print up in that row. 
   }
}

I usually use two int variables, "r" and "c" or "i" and "j" for this. Laid out like the above pattern, it's not too tough. All that other code is ready for the dustbin. You can see how hard it is to code up a simple assignment, when you don't have a plan.

Since our pattern repeats but in an upside down way, you may want to do half of it, and then do the other half, in a second nested pair like the first, but with different logic.

eitherway waltp is right. this program ain't got any use to anyone! whats the use of improving the code? make useful stuff, these kind of programs are for learning C. They don't need any improvements!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.