C Program to Find Largest of Three Numbers Using Pointer

This C program finds largest of three numbers using pointer.

C Source Code: Largest of Three Numbers Using Pointer


#include<stdio.h>

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

 printf("Enter three numbers:\n");
 scanf("%d%d%d", &a,&b,&c);
 
 /* Referencing */
 pa= &a;
 pb= &b;
 pc= &c;
 if(*pa > *pb && *pa > *pc)
 {
  printf("Largest is: %d", *pa);
 }
 else if(*pb > *pc && *pb > *pc)
 {
  printf("Largest is : %d", *pb);
 }
 else
 {
  printf("Largest = %d", *pc);
 }
 return 0;
}

Output

Run 1:
Enter three numbers: 
12↲
33↲
-17↲
Largest = 33

Run 2:
Enter three numbers: 
-18↲
-31↲
-17↲
Largest = -17

Run 3:
Enter three numbers: 
118↲
19↲
-87↲
Largest = 118

Note: ↲ indicates enter is pressed.