Multiply two numbers and display the result for as long as the user wants. Answering 'N' will break the loop - C Operator

C examples for Operator:Arithmetic Operator

Description

Multiply two numbers and display the result for as long as the user wants. Answering 'N' will break the loop

Demo Code

#include <stdio.h>
int main()/*from w w  w .j a v a 2 s . com*/
{
    float num1, num2, result;
    char choice;
    do {
        printf("Enter your first number to multiply: ");
        scanf(" %f", &num1);

        printf("Enter your second number to multiply: ");
        scanf(" %f", &num2);

        result = num1 * num2;

        printf("%.2f times %.2f equals %.2f\n\n", num1, num2, result);

        printf("Do you want to enter another pair of numbers ");
        printf("to multiply (Y/N): ");
        scanf(" %c", &choice);

        if (choice == 'n') {
            choice = 'N';
        }
    } while (choice != 'N');

    return 0;

}

Result


Related Tutorials