BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Find the Largest of three numbers using Pointers

Last Updated: February 25, 2019 by Chaitanya Singh | Filed Under: C Programs

In this tutorial, we will write a C program to find the largest of three input numbers using pointers.

Program to find largest number using pointers

In the following program we have three integers num1, num2 & num3. We have assigned the addresses of these three numbers to three pointers p1, p2 & p3 respectively. Later we performed the comparison on the values stored at the addresses pointed by pointers using if else statement.

#include <stdio.h>
int main()
{
    int num1, num2, num3;
    int *p1, *p2, *p3;

    //taking input from user
    printf("Enter First Number: ");
    scanf("%d",&num1);
    printf("Enter Second Number: ");
    scanf("%d",&num2);
    printf("Enter Third Number: ");
    scanf("%d",&num3);

    //assigning the address of input numbers to pointers
    p1 = &num1;
    p2 = &num2;
    p3 = &num3;
    if(*p1 > *p2)
    {
	if(*p1 > *p3)
	{
		printf("%d is the largest number", *p1);
	}
	else
	{
		printf("%d is the largest number", *p3);
	}
    }
    else
    {
	if(*p2 > *p3)
	{
		printf("%d is the largest number", *p2);
	}
	else
	{
		printf("%d is the largest number", *p3);
	}
    }
    return 0;
}

Output:
C Program to Find the Largest of three numbers using Pointers

Related C Examples

1. C program to count vowels and consonants in a String using Pointer
2. C program to print a String using Pointer
3. C program to swap two numbers using Pointers
4. C program to create initialize and access a pointer variable
5. C program to find the largest of three numbers without using pointers

Top Related Articles:

  1. C Program to calculate Area of an Equilateral triangle
  2. C Program to find the Size of int, float, double and char
  3. C Program to Find GCD of two Numbers
  4. C Program to Generate Multiplication Table
  5. C Program to concatenate two strings without using strcat

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Ert1 Collaku says

    March 27, 2020 at 9:03 AM

    How can i do the opposite? I am trying to change the arrows from > to < but nothing I am new and i was trying to learn from this ex.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap