Answer to Question #300709 in C for Justin

Question #300709

Create a program based on the attached 3 outputs below. Using a while loop is required in your program



Sample output 1:


Choices


E or e for Even


O or o for Odd


X or X for Exit



Enter your choices: e


.........This program is for Multiplication of even numbers........



Enter a number:20


1 * 2=2


2 * 4=8


3 * 6=18


4 * 8=32


5 * 10= 50


6 * 12=72


7 * 14=98


8 * 16=128


9 * 18=162


10 *20= 200




Sample output 2:



Choices


E or e for Even


O or o for Odd


X or X for Exit



Enter your choice:o



.....This program is for Multiplication of Odd numbers....



Enter a number:10



1 * 1=1


2 * 3=6


3 * 5=15


4 * 7=28


5 * 9=45




Sample output 3:


Choices


E or e for Even


O or o for Odd


X or X for Exit



Enter your choice:X


Your program will now exit.




1
Expert's answer
2022-02-21T15:02:48-0500
#include <stdio.h>
    
int main()
{
    char option;
    int a;
    do {
    printf("Choices\n");
    printf("E or e for Even\n");
    printf("O or o for Odd\n");
    printf("X or X for Exit\n\n");
    printf("Enter your choices: ");
    scanf("%c", &option);

    if (option == 'E' || option == 'e')
    {
        printf("\n.........This program is for Multiplication of even numbers........\n\n");
        printf("Enter a Number: ");
        scanf("%d", &a);
        for (int i = 1; i <= a/2; i++)
        {
        printf("%d*%d = %d\n", i, (i*2), i*((i*2)));
        }
    }
    else if (option == 'O' || option == 'o')
    {
        printf("\n.....This program is for Multiplication of Odd numbers....\n\n");
        printf("Enter a Number: ");
        scanf("%d", &a);
        for (int i = 1; i <= a/2; i++)
        {
        printf("%d*%d = %d\n", i, (i*2)-1, i*((i*2)-1));
        }
    }
    else if (option == 'X')                        // if and 'x' - replace  else if (option == 'X' || option == 'x')    
        printf("\nYour program will now exit.");
    else
        printf("\nInvalid option\n\n");
    printf("\n");
    getchar();    
    } while (option != 'X');            // if and 'x' - replace  while (option != 'X' || option != 'x')    
     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