0% found this document useful (0 votes)
27 views

Multiplication of Two Numbers

Uploaded by

amoghmemories2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Multiplication of Two Numbers

Uploaded by

amoghmemories2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Here’s a C program to multiply two numbers along with a detailed explanation:

#include <stdio.h> // Include standard input-output header file

int main() {

int num1, num2, product; // Declare variables to store two numbers and their product

// Prompt the user for input

printf("Enter the first number: ");

scanf("%d", &num1); // Read the first number from the user

printf("Enter the second number: ");

scanf("%d", &num2); // Read the second number from the user

// Perform multiplication

product = num1 * num2;

// Display the result

printf("The product of %d and %d is %d\n", num1, num2, product);

return 0; // Indicate that the program ended successfully

Explanation of the Program:

1. Header File:

o #include <stdio.h>: Required for scanf and printf functions to handle input and
output.

2. Variable Declaration:

o int num1, num2, product;: Declares three integer variables. num1 and num2 will
store user inputs, and product will store the result of their multiplication.

3. Input:

o printf("Enter the first number: ");: Prompts the user to input the first number.

o scanf("%d", &num1);: Reads the integer input from the user and stores it in num1.

o Similarly, the second number is read and stored in num2.


4. Multiplication:

o product = num1 * num2;: The values of num1 and num2 are multiplied and stored in
the variable product.

5. Output:

o printf("The product of %d and %d is %d\n", num1, num2, product);: Displays the


multiplication result. The %d format specifier is used for integers.

6. Return Statement:

o return 0;: Indicates successful execution of the program.

Sample Output:

Enter the first number: 7

Enter the second number: 8

The product of 7 and 8 is 56

You can compile and run this program using any C compiler:

• Compile: gcc multiply_numbers.c -o multiply_numbers

• Run: ./multiply_numbers

You might also like