Categories: category

C program to find product two numbers using pointer

C program to find the product of two numbers using pointer

In this tutorial, we will discuss C program to find product two numbers using pointer

In the C programming  language, we can use the pointer variable to find product of two numbers .

In this article, we are going to learn  how to display the product of two numbers using the pointer variable.

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2;      //1
    int *ptr1,*ptr2;    //2
    int mul;              //3

    printf("Please enter value for num1: ");    //4
    scanf("%d",&num1);                           //5
    printf("Please enter value for num2: ");      //6
    scanf("%d",&num2);                             //7

    ptr1=&num1;                                      //8
    ptr2=&num2;

    mul=*ptr1 * *ptr2;                                 //10

    printf("Product of the two integer values is: %d",mul);  //11
    getch();
    return 0;
}

When the above code is executed, it produces the following results

Please enter a value for num1: 12
Please enter a value for num2: 11
Product of the two integer values is: 132

 

Methods

  1. Create two variables to store two numbers as input (num1 and num2) provided by the user.
  2. Create two pointer variables to store the address of the numbers: num 1 and num2
  3. Create a variable to store the sum of these numbers: sum.
  4. Request the user to enter the first input to store variable num1
  5. Using scanf() function, store the first input value in num1
  6. Request the user to enter the second number to store as variable num2
  7. Using scanf() function, store the second input value in num2.
  8. Assign the address of variable num1 to ptr1
  9. Assign the address of variable num2 to ptr2
  10. Find the product of two number using their addresses – find the product of num1 and num2 using their addresses or multiply them using the pointer variables.
  11. Finally, display result on the screen- the product of both numbers num1 and num1

 

Similar post

C program to add two numbers

C program to add two numbers using the pointer

C++ program to add two numbers

C program to find the product of two numbers

 

Suggested for you

Input-output function in C language

Data type in C language

Variable in C language

Operator n C language

Pointer in C language

 

 

Display integrated pyramid star pattern in C++ using while loop
Calculate product of two floating point numbers in Python
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago