C Examples Multiplication

Real-Time Uses of Multiplication

  1. Financial Calculations
    • Calculating total price: price * quantity
    • Interest calculation: principal * rate
  2. Physics and Engineering
    • Area of a rectangle: length * width
    • Volume: length * width * height
    • Force calculation: mass * acceleration
  3. Data Analysis & Statistics
    • Weighted averages: value * weight
    • Scaling datasets: multiplying each data point by a factor
  4. Embedded Systems & IoT
    • Sensor calibration: raw_value * calibration_factor
    • Real-time computation in control systems
  5. Computer Graphics
    • Scaling images: pixel_coordinate * scale_factor
    • Calculating transformations in 2D/3D graphics

C Program for Two Floating-Point Multiplication

The program accepts two numbers from the user, multiplies them, and displays the product with precision up to two decimal places.

#include <stdio.h>


void main()
{
    double first_num, second_num, product;
    printf("Enter two numbers: ");

    // Stores two floating point numbers in variables
    scanf("%lf %lf", &first_num, &second_num);

    // Performs multiplication and stores the result in variable product
    product = first_num * second_num;

    // Result up to 2 decimal point is displayed using %.2lf
    printf("Product of %f * %f = %.2lf", first_num, second_num,product);
}

Output:

Enter two numbers:
8.2
1.5
Product of 8.200000 * 1.500000 = 12.30
--------------------------------
Process exited after 12.78 seconds with return value 38
Press any key to continue . . .

Explanation:

Code Explanation

#include <stdio.h>
  • Includes the standard input/output library for using printf and scanf.
void main()
{
    double first_num, second_num, product;
  • Declares three double precision variables:
    • first_num → First input number
    • second_num → Second input number
    • product → Stores the result of multiplication
printf("Enter two numbers: ");
scanf("%lf %lf", &first_num, &second_num);
  • Prompts the user to enter two numbers.
  • %lf format specifier is used for double type inputs.
product = first_num * second_num;
  • Performs multiplication of the two numbers and stores the result in product.
printf("Product of %f * %f = %.2lf", first_num, second_num, product);
  • Displays the product:
    • %f → Prints first_num and second_num
    • %.2lf → Prints product rounded to 2 decimal places

C Program to Convert Inch to Feet

Pr-Request to learn

  • Preprocessor command #
  • Header file
  • Variable declare & define
  • Multiplication * operator
  • printf() function

Code:

#include<stdio.h>

int main()
{
    int inches, feet;
    feet = 10;
    inches = feet*12;
    printf("there are %d inches in %d feet./n", inches, feet);
}

Output: there are 120 inches in 10 feet

Code Explanation:

  • #include<stdio.h> is a standard input output header file.
  • C requires a ; semicolon at every end of the statement.
  • printf() is a standard C function (Called from main)
  • \n signifies a new line.

Previous & Next


Please turn AdBlock off, and continue learning

Notice for AdBlock users

Please turn AdBlock off
Index

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading