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;
}
0 Comments
I really appreciate for your words. Thank you very much for your comment.