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:
while (index<num){
while
condition edited.for (int i=index-1; >= 0; i--)
for
edited index 0.- num--; not required.
while (index<num){ // makes spaces (int i=index-1; >= 0; i--) { printf(" "); } printf("*"); printf("\n"); //num--; index++; }
Comments
Post a Comment