Learn about Largest among three number using pointer & function in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Largest among three number using pointer & function in C
User-defined function find is defined to get large number among three numbers. To get this pointer is passed as parameter to the function. Variable declared is assigned to the pointer.
#include<stdio.h>
void find(int *x, int *y, int *z);
int main()
{
int a, b, c;
int *pa, *pb, *pc;
pa= &a, pb= &b, pc=&c;
printf("Enter three number: ");
scanf("%d %d %d", pa, pb, pc);
find(pa, pb, pc);
return 0;
}
void find(int *x, int *y, int *z)
{
if( (*x > *y) && (*x > *z) )
printf("Largest = %d", *x);
else if((*y > *x) && (*y > *z))
printf("Largest = %d", *y);
else
printf("Largest = %d", *z);
}
Output:
Enter three number: 78 99 32
Largest = 99
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C Program to find Largest among three number using the pointer
Find Area of Circle Using Pointer & Function in C