Table of Contents
ToggleIn this blog post, we will checkout the C Program for Multiplication of Two Numbers.
Algorithm to Add Two Numbers in C
To create a C Program for Multiplication of Two Numbers, you can follow this algorithm.
Algorithm:
- Start: Begin the process.
- Input two numbers: Prompt the user to input the two numbers.
- Multiply both the numbers: Use the formula num1 * num2 to calculate the multiplication.
- Display answer: Show the calculated answer to the user.
- End: Conclude the process.
C Program to Multiply Two Numbers
#include <stdio.h>
int main() {
double num1, num2, product;
// Ask the user for two numbers
printf("Enter first number: ");
scanf("%lf", &num1);
printf("Enter second number: ");
scanf("%lf", &num2);
// Multiply the numbers
product = num1 * num2;
// Display the result
printf("The multiplication of %lf and %lf: %.2lf\n", product);
return 0;
}
Output
Explanation
- Step 1: The program starts by including the standard input-output library
stdio.h
for basic input/output operations. - Step 2: In the
main
function, three integer variables are declared:number1
,number2
, andresult
. - Step 3: The program then prompts the user to enter the first and second numbers, which are read and stored in
number1
andnumber2
respectively usingscanf
. - Step 4: The product is calculated.
- Step 5: Finally, the program prints the result using
printf
.
Time Complexity: The time complexity of this program is O(1).
Space Complexity: The space complexity of the program is also O(1).
If you liked this post you can checkout other C Programs.