Loops not incrementing correctly in C -


hello i'm new c i'm using c99 compile , i'm making program prints different shapes using *.

i'm having issue making diagonal line here code i'm using while loop nested loop inside of switch statement.

if tell there 5 * 3 in return , if give number 7 4. spacing works correctly isn't finishing out loop.

any great!

case 'd':     printf("size: ");     scanf("%d", &num);     index =0;     while (index<=num){ // makes spaces     (int i=0; i<num-1; i++){             printf(" ");     }     printf("*");     printf("\n");     num--;     index++;     }                  break; 

input size: 5 output: * * *

try code below.. shoud draw diagonal you.

changes:

  1. while (index<num){ while condition edited.
  2. for (int i=index-1; >= 0; i--) for edited index 0.
  3. num--; not required.
while (index<num){         // makes spaces         (int i=index-1; >= 0; i--)         {             printf(" ");         }         printf("*");         printf("\n");         //num--;         index++;     }  

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -