Learn about C Program to find Largest among three number using the pointer in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
C Program to find Largest among three number using the pointer
We have three numbers x, y, and z in the following program. The addresses of these three numbers have been given to three pointers, px, py, and pz, correspondingly. Using an if else statement, we later performed a comparison on the values stored at the positions specified by pointers.
#include<stdio.h>
int main()
{
float x, y, z;
float *px, *py, *pz;
px=&x, py=&y, pz=&z;
printf("Enter three number:");
scanf("%f %f %f", px, py, pz);
if(*px > *py)
{
if(*px > *pz)
printf("Biggest = %.2f", *px);
else
printf("Biggest = %.2f", *pz);
}
else
{
if(*py > *pz)
printf("Biggest = %.2f", *py);
else
printf("Biggest = %.2f", *pz);
}
return 0;
}
Output:
Enter three number:55 67 45
Biggest = 67.00
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Find Area of Circle Using Pointer & Function in C
C Program to find Area of Circle Using Pointer