C Examples Multiplication
Real-Time Uses of Multiplication
- Financial Calculations
- Calculating total price:
price * quantity - Interest calculation:
principal * rate
- Calculating total price:
- Physics and Engineering
- Area of a rectangle:
length * width - Volume:
length * width * height - Force calculation:
mass * acceleration
- Area of a rectangle:
- Data Analysis & Statistics
- Weighted averages:
value * weight - Scaling datasets: multiplying each data point by a factor
- Weighted averages:
- Embedded Systems & IoT
- Sensor calibration:
raw_value * calibration_factor - Real-time computation in control systems
- Sensor calibration:
- Computer Graphics
- Scaling images:
pixel_coordinate * scale_factor - Calculating transformations in 2D/3D graphics
- Scaling images:
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
printfandscanf.
void main()
{
double first_num, second_num, product;
- Declares three double precision variables:
first_num→ First input numbersecond_num→ Second input numberproduct→ Stores the result of multiplication
printf("Enter two numbers: ");
scanf("%lf %lf", &first_num, &second_num);
- Prompts the user to enter two numbers.
%lfformat 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→ Printsfirst_numandsecond_num%.2lf→ Printsproductrounded 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)\nsignifies a new line.
Previous & Next
- Previous : C Examples Addition
- Next : C Examples Time Delay