Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add a do-while loop in this program so that if the input is less than 4 it doesn't print anything

#include <stdio.h>

int main () {

    int row, i, j;

    printf("Enter a number: ");
    scanf("%d", &row);

        for (i=1; i<=row; i++) {

        for (j=1; j<=row; j++) {

            if (i==1 || i==row || i+j==row+1) {

                printf("*");
            }
            else 
            {
            printf(" ");
            }
        }
        printf("\n");
    }
    printf("\n\n");
    }
    return 0;
}

The program prints out the letter "Z" out of stars.
I have to add a do-while loop in this. (This is for school, you can clearly see that I’m a begginer.)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Perhaps this is what you want:

do {
    printf("Enter a number: ");
    scanf("%d", &row);
    if (row < 4) puts("Try again");
} while (row < 4);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading