C Online Compiler
Example: Greatest of Three Numbers in C using Pointers
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Greatest of Three Numbers in C using Pointers #include <stdio.h> // It's the main function of the program int main() { int num1, num2, num3; int *p_num1, *p_num2, *p_num3; // Step-1 Enter three integer values printf("INPUT-1: "); scanf("%d", &num1); printf("INPUT-2: "); scanf("%d", &num2); printf("INPUT-3: "); scanf("%d", &num3); // Step-2 Reference the values to pointer variables p_num1 = &num1; p_num2 = &num2; p_num3 = &num3; // Step-2 Check if p_num1 is greater than both p_num2 and p_num3, p_num1 is the greatest if (*p_num1 >= *p_num2 && *p_num1 >= *p_num3) { printf("\nGreatest Number :: %d", *p_num1); } // Step-3 Check if p_num2 is greater than both p_num1 and p_num3, p_num2 is the greatest else if (*p_num2 >= *p_num1 && *p_num2 >= *p_num3) { printf("\nGreatest Number :: %d", *p_num2); } // Step-4 If above both conditions are false then, p_num3 is the greatest else { printf("\nGreatest Number :: %d", *p_num3); } return 0; }
90 40 10
Output
Clear
ADVERTISEMENTS