Answer to Question #193422 in C for sai

Question #193422

Write a program to print all even numbers between 0 and an integer number entered by

the user using:

a. For loop

b. While loop

c. Do while loop


1
Expert's answer
2021-05-16T12:23:36-0400
#include <stdio.h>


int main()
{
    int number;
    printf("Enter number: ");


    scanf("%d", &number);


    int i;
    for(i = 0; i < number; i+=2)
        printf("%d ", i);


    printf("\n");


    i = 0;
    while(i < number)
    {
        printf("%d ", i);
        i +=2;
    }
    printf("\n");


    i = 0;
    do
    {
        printf("%d ", i);
        i+=2;
    }while(i < number);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS