C Program to Find the Largest of Three Numbers using a Pointer

Write a C program to find the largest of three numbers using a pointer. First, we assign the user entered three integers to pointers. Next, this c example uses the nested if else statements to check and find the largest pointer number among the three.

#include <stdio.h>

int main()
{
  int a, b, c, *pa, *pb, *pc;

  printf("Please Enter three Number to find Largest\n");
  scanf("%d %d %d", &a, &b, &c);

  pa = &a;
  pb = &b;
  pc = &c;

  if (*pa > *pb)
  {
    if(*pa > *pc)
    {
      printf("\nThe Largest Among Three = %d\n", *pa);
    }
    else
    {
      printf("\nThe Largest Among Three = %d\n", *pc);
    }
  }
  else
  {
    if(*pb > *pc)
    {
      printf("\nThe Largest Among Three = %d\n", *pb);
    }
    else
    {
      printf("\nThe Largest Among Three = %d\n", *pc);
    }
  }
}
C Program to Find the Largest of Three Numbers using a Pointer

This c program uses the else if statements and pointer to find the largest of three numbers.

#include <stdio.h>
int main()
{
  int a, b, c, *pa, *pb, *pc;

  printf("Please Enter three Number to find Largest\n");
  scanf("%d %d %d", &a, &b, &c);

  pa = &a;
  pb = &b;
  pc = &c;

  if (*pa > *pb && *pa > *pc)
  {
    printf("\nThe Largest Among Three = %d\n", *pa);
  }
  else if (*pb > *pa && *pb > *pc)
  {
    printf("\nThe Largest Among Three = %d\n", *pb);
  }
  else if (*pc > *pa && *pc > *pb)
  {
    printf("\nThe Largest Among Three = %d\n", *pc);
  }
}
Please Enter three Number to find Largest
19
90
120

The Largest Among Three = 120

In this c example, we used the nested conditional operator and pointer to find the largest among three numbers.

#include<stdio.h>

int main()
{
  int a, b, c, *pa, *pb, *pc, *largest;

  printf("Please Enter three Number to find Largest\n");
  scanf("%d %d %d", &a, &b, &c);

  pa = &a;
  pb = &b;
  pc = &c;

 largest =((*pa > *pb && *pa > *pc)? pa: (*pb > *pc) ? pb : pc);
 printf("\nThe Largest number Among three = %d\n", *largest);
 return 0;
}
Please Enter three Number to find Largest
22
44
19

The Largest number Among three = 44