WAP to display even numbers using while and do while loops.-NEB-computer 12




Display even numbers using while and do while loops

#include <stdio.h>
int main() {
    int num = 1;
    // Using while loop to display even numbers
    printf("Even numbers using while loop:\n");
    while (num <= 20) {
        if (num % 2 == 0) {
            printf("%d ", num);
        }
        num++;
    }
    printf("\n");
    // Resetting num for do while loop
    num = 1;
    // Using do while loop to display even numbers
    printf("Even numbers using do while loop:\n");
    do {
        if (num % 2 == 0) {
            printf("%d ", num);
        }
        num++;
    } while (num <= 20);
    printf("\n");
    return 0;
}

Post a Comment

0 Comments